From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by sourceware.org (Postfix) with ESMTPS id 2681D3858C66 for ; Wed, 7 Feb 2024 20:11:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2681D3858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2681D3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707336708; cv=none; b=hhfBtiommka+zB2ncgTgLOfhS4De1fYZHbILYiEmo85uABAdvzVlMSJpk94jUmX6EuRYSD2VLwkotlTxFWaqTs+jB5mslvgvV8NfERo9J2TASmaP6hSH5KaLQTLFCC08d2K8eyiYIOOfluie5Tx0JpGA0eYreJ9JMkdr7IoJYO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707336708; c=relaxed/simple; bh=NrD7UbQr8YKXxUzunJoWd26e13HQ8kRV07a4jgI8fuM=; h=Message-ID:Date:MIME-Version:Subject:From:To; b=gJqvZqzSpeCr8tnHk6PG7NLL+T4e9yWIlywqZa5IEbz6JWsS0jHuLUvBTQM7sTK1uYJYMZRkZ7h5rCM9fo7YcP62TLZtW7vNDgbyFjJacaHWExHx0QUTBh+EzoWsVQ/auPmM6YFPF6NPYRdN8UsHtFcVqqGwiDcP8N/ykrNojfM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4101d4c5772so1266545e9.0 for ; Wed, 07 Feb 2024 12:11:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707336705; x=1707941505; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+r9RO6laWqMUSKSgngRT9VSs8cdeS8EU/nBViNk2q2I=; b=gHuOt9PMNr9o2rJhqoWfYbw/PF0FYzMiB0yVOJeJO0lis0+EeL8b1FmW7VPqJ7s4H8 nttd0eckOqbFqUD8OCgbq0X0vkwQNNv4W8d7ywg26YzyOa5pLvQRgEG9hynqCCVtH50E 6VPpJWnzJ51w3rKRrKGAmpgxwQ+AdNtLAifxN5SPavdc4r02Qkc1TuAGmvKnw94MPgUO eVln6K1TEc/5/g3CNE9M9HV1q4Hrbo3h5dwCTnojpa4N5iCJ4wpWoFo11f2l2l/EuOv1 R3iBXVFUvGTv0psZwLieDCa+0FQnQkwIslQYxK1USX2zYBTqTGVC5JyqjoeqR0ta2muf 8hUg== X-Forwarded-Encrypted: i=1; AJvYcCU7729ir7/G86cSnVj35zW66+uT1P9snPAIJ95NG+psKCIIn104ifR3B739e+JC22GegJZia2jDzaNKrwn0t1CHyWO9MgLhY/MfVQ== X-Gm-Message-State: AOJu0YyQ3Ru0WBR7JOF4E6bhiKr98DAIkRFOvMZboopOcOEZTJcVY3kr BNG3VFcn510SkM6H/1CQSvWAPAUOYFYI7htiUirHoKqa1E1ryYZD X-Google-Smtp-Source: AGHT+IFNAxKH/6S6dXuQjOfhesNCXAJDV6rX1aR+y9MBZTSTfRFBVHUW5BPyTOlqo74hJQzBBy2ruA== X-Received: by 2002:a05:600c:4750:b0:40f:251:4ff6 with SMTP id w16-20020a05600c475000b0040f02514ff6mr406652wmo.3.1707336704502; Wed, 07 Feb 2024 12:11:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVGiUgOveCePn4FbYs0Uwl/ZU2nrupfDFgCc2ucQ5zzU5XGCyVnalKf06+v4A1I7QEsvgdb+j+AnepiPxZriMvcbul7TSOY1TRz/qFzrj+mLrZ/wjKX++ED/uDGC5OQTk/82h+rScrFOTFjAUNP532kz2WdBXE= Received: from ?IPV6:2001:8a0:f923:4f00:d1ab:b98b:8238:4b55? ([2001:8a0:f923:4f00:d1ab:b98b:8238:4b55]) by smtp.gmail.com with ESMTPSA id v9-20020a05600c470900b0040fe2d3aec4sm6238037wmo.19.2024.02.07.12.11.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Feb 2024 12:11:44 -0800 (PST) Message-ID: <82b48b9e-710e-404b-b0bf-8b245a7ca632@palves.net> Date: Wed, 7 Feb 2024 20:11:43 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [FYI/pushed v4 08/25] Thread options & clone events (Linux GDBserver) Content-Language: en-US From: Pedro Alves To: Tom Tromey , Luis Machado Cc: Simon Marchi , gdb-patches@sourceware.org, Andrew Burgess References: <20231113150427.477431-1-pedro@palves.net> <20231113150427.477431-9-pedro@palves.net> <87eddpej3r.fsf@tromey.com> <2e61811c-ff0f-44d0-bf6f-e98a9de87c33@arm.com> <87mssccmb3.fsf@tromey.com> <27777234-0335-4ef1-bc2b-34324d335e30@arm.com> <87sf24b0jd.fsf@tromey.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2024-02-07 18:56, Pedro Alves wrote: > Hi! > > On 2024-02-07 18:18, Tom Tromey wrote: >>>>>>> "Luis" == Luis Machado writes: >> >> Luis> I see. Is this logic expected? Naturally I'd expect a process to >> Luis> exist before a thread can exist. >> >> Me too but you can see it in >> linux-low.cc:linux_process_target::handle_extended_wait. >> >> lwp_info *child_lwp = add_lwp (child_ptid); >> [...] >> if (event != PTRACE_EVENT_CLONE) >> { >> /* Add the new process to the tables and clone the breakpoint >> lists of the parent. We need to do this even if the new process >> will be detached, since we will need the process object and the >> breakpoints to remove any breakpoints from memory when we >> detach, and the client side will access registers. */ >> process_info *child_proc = add_linux_process (new_pid, 0); >> [...] >> > > I don't recall off hand a reason that prevents us from tweaking this code a little to > create the child process before the child lwp is created. I think that was how it was > done before my changes, and I just reordered code to make it end up with fewer lines. > I think we can create the child process earlier. > > I'll send a patch in a sec, once I test it. Like so? Does it fix the crash? >From 0c308ac13c4537c885491305cee7215fbfdf04c0 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 7 Feb 2024 18:48:16 +0000 Subject: [PATCH] Fix crash in aarch64-linux gdbserver Since commit 393a6b5947d0 ("Thread options & clone events (Linux GDBserver)"), aarch64-linux gdbserver crashes when the inferior vforks. This happens in aarch64_get_debug_reg_state: struct process_info *proc = find_process_pid (pid); return &proc->priv->arch_private->debug_reg_state; Here, find_process_pid returns nullptr -- the new inferior hasn't yet been created in linux_process_target::handle_extended_wait. This patch fixes the problem by having linux_process_target::handle_extended_wait create the child process earlier, before the child LWP is created. This is what the function did before it was reorganized by the commit referred above. Change-Id: Ib8b3a2e6048c3ad2b91a92ea4430da507db03c50 Co-Authored-By: Tom Tromey --- gdbserver/linux-low.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 444eebc6bbe..9d5a6242803 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -555,6 +555,16 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, ? ptid_t (new_pid, new_pid) : ptid_t (ptid_of (event_thr).pid (), new_pid)); + process_info *child_proc = nullptr; + + if (event != PTRACE_EVENT_CLONE) + { + /* Add the new process to the tables before we add the LWP. + We need to do this even if the new process will be + detached. See breakpoint cloning code further below. */ + child_proc = add_linux_process (new_pid, 0); + } + lwp_info *child_lwp = add_lwp (child_ptid); gdb_assert (child_lwp != NULL); child_lwp->stopped = 1; @@ -588,12 +598,11 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, if (event != PTRACE_EVENT_CLONE) { - /* Add the new process to the tables and clone the breakpoint - lists of the parent. We need to do this even if the new process - will be detached, since we will need the process object and the - breakpoints to remove any breakpoints from memory when we - detach, and the client side will access registers. */ - process_info *child_proc = add_linux_process (new_pid, 0); + /* Clone the breakpoint lists of the parent. We need to do + this even if the new process will be detached, since we + will need the process object and the breakpoints to + remove any breakpoints from memory when we detach, and + the client side will access registers. */ gdb_assert (child_proc != NULL); process_info *parent_proc = get_thread_process (event_thr); base-commit: 6fb99666f4bbc79708acb8efb2d80e57de67b80b -- 2.43.0