From: Luis Machado <luis.machado@arm.com>
To: Pedro Alves <pedro@palves.net>, Tom Tromey <tromey@adacore.com>
Cc: Simon Marchi <simark@simark.ca>,
gdb-patches@sourceware.org, Andrew Burgess <aburgess@redhat.com>
Subject: Re: [FYI/pushed v4 08/25] Thread options & clone events (Linux GDBserver)
Date: Thu, 8 Feb 2024 08:57:03 +0000 [thread overview]
Message-ID: <4ad04baa-287f-41ce-8c13-45bc8091edee@arm.com> (raw)
In-Reply-To: <82b48b9e-710e-404b-b0bf-8b245a7ca632@palves.net>
Hi!
On 2/7/24 20:11, Pedro Alves wrote:
> On 2024-02-07 18:56, Pedro Alves wrote:
>> Hi!
>>
>> On 2024-02-07 18:18, Tom Tromey wrote:
>>>>>>>> "Luis" == Luis Machado <luis.machado@arm.com> 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?
It does, thanks for the quick patch.
Maybe before this series we were relying on some other path eventually creating a process first, and
the new code somehow caused a (indirect?) change.
I'm putting this through the gdbserver testsuite on my end. I'll let you know what comes out of it.
>
> From 0c308ac13c4537c885491305cee7215fbfdf04c0 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <pedro@palves.net>
> 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 <tromey@adacore.com>
> ---
> 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
next prev parent reply other threads:[~2024-02-08 8:57 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-13 15:04 [FYI/pushed v4 00/25] Step over thread clone and thread exit Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 01/25] Add "maint info linux-lwps" command Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 02/25] gdb/linux: Delete all other LWPs immediately on ptrace exec event Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 03/25] Step over clone syscall w/ breakpoint, TARGET_WAITKIND_THREAD_CLONED Pedro Alves
2023-11-14 12:55 ` Guinevere Larsen
2023-11-14 13:26 ` Pedro Alves
2023-11-14 16:29 ` Guinevere Larsen
2023-11-14 16:44 ` Luis Machado
2023-11-14 13:28 ` Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 04/25] Support clone events in the remote protocol Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 05/25] Avoid duplicate QThreadEvents packets Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 06/25] Thread options & clone events (core + remote) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 07/25] Thread options & clone events (native Linux) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 08/25] Thread options & clone events (Linux GDBserver) Pedro Alves
2024-02-06 11:04 ` Luis Machado
2024-02-06 14:57 ` Tom Tromey
2024-02-06 15:12 ` Luis Machado
2024-02-07 8:59 ` Luis Machado
2024-02-07 15:43 ` Tom Tromey
2024-02-07 17:10 ` Simon Marchi
2024-02-07 18:05 ` Luis Machado
2024-02-07 18:18 ` Tom Tromey
2024-02-07 18:56 ` Pedro Alves
2024-02-07 20:11 ` Pedro Alves
2024-02-08 8:57 ` Luis Machado [this message]
2024-02-08 10:53 ` Pedro Alves
2024-02-08 11:47 ` Luis Machado
2024-02-08 14:58 ` Tom Tromey
2024-02-07 18:06 ` Tom Tromey
2023-11-13 15:04 ` [FYI/pushed v4 09/25] gdbserver: Hide and don't detach pending clone children Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 10/25] Remove gdb/19675 kfails (displaced stepping + clone) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 11/25] all-stop/synchronous RSP support thread-exit events Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 12/25] gdbserver/linux-low.cc: Ignore event_ptid if TARGET_WAITKIND_IGNORE Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 13/25] Move deleting thread on TARGET_WAITKIND_THREAD_EXITED to core Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 14/25] Introduce GDB_THREAD_OPTION_EXIT thread option, fix step-over-thread-exit Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 15/25] Implement GDB_THREAD_OPTION_EXIT support for Linux GDBserver Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 16/25] Implement GDB_THREAD_OPTION_EXIT support for native Linux Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 17/25] gdb: clear step over information on thread exit (PR gdb/27338) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 18/25] stop_all_threads: (re-)enable async before waiting for stops Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 19/25] gdbserver: Queue no-resumed event after thread exit Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 20/25] Don't resume new threads if scheduler-locking is in effect Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 21/25] Report thread exit event for leader if reporting thread exit events Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 22/25] gdb/testsuite/lib/my-syscalls.S: Refactor new SYSCALL macro Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 23/25] Testcases for stepping over thread exit syscall (PR gdb/27338) Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 24/25] Document remote clone events, and QThreadOptions packet Pedro Alves
2023-11-13 15:04 ` [FYI/pushed v4 25/25] Cancel execution command on thread exit, when stepping, nexting, etc Pedro Alves
2023-11-13 19:28 ` [FYI/pushed v4 00/25] Step over thread clone and thread exit Tom de Vries
2023-11-14 10:51 ` Pedro Alves
2023-11-14 13:39 ` Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ad04baa-287f-41ce-8c13-45bc8091edee@arm.com \
--to=luis.machado@arm.com \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=pedro@palves.net \
--cc=simark@simark.ca \
--cc=tromey@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).