From: Pedro Alves <pedro@palves.net>
To: simon.marchi@polymtl.ca, gdb-patches@sourceware.org
Subject: Re: [PATCH] gdbserver/linux-low: carry over stop_expected flag after exec (avoid spurious SIGSTOPs)
Date: Fri, 26 Jun 2026 18:35:20 +0100 [thread overview]
Message-ID: <a3dcf9e7-9a4d-4c19-abf5-8d6ba85b2f73@palves.net> (raw)
In-Reply-To: <20260626143242.4033142-1-simon.marchi@polymtl.ca>
On 2026-06-26 15:32, simon.marchi@polymtl.ca wrote:
> What about GDB
> ==============
>
> I tried to check if the same bug could happen with GDB's linux-nat
> target, and if the same fix was needed. linux-nat takes a different
> approach when handling PTRACE_EVENT_EXEC. It wipes all lwp_infos except
> the leader:
>
> for (lwp_info &other_lp : all_lwps_safe ())
> if (&other_lp != lp && other_lp.ptid.pid () == lp->ptid.pid ())
> exit_lwp (&other_lp);
>
> Here, LP is an lwp_info obtained using the event ptid of the
> PTRACE_EVENT_EXEC, therefore the leader's lwp_info (even if the exec was
> done by a non-leader).
>
> If the exec is done by the leader, as is the case with
> gdb.base/vfork-follow-parent.exp, we are ok. Because GDB doesn't delete
> and re-create the lwp_info, the equivalent of GDBserver's
> `lwp_info::stop_expected`, `lwp_info::signalled`, survives the exec.
>
> If the exec is done by a non-leader, then we could be in trouble. If
> the leader's signalled flag is not set, but the exec'ing non-leader's
> flag is set, then we'll lose it. I suppose we could fix GDB to use
> PTRACE_GETEVENTMSG to get the exec'ing thread former id, look up the
> lwp_info for that id, and preserve that lwp_info.
Yeah, it'd be good to fix GDB too. This sort of bug is hard to track
down, and we already know we have it.
> + unsigned long execing_tid = event_ptid.lwp ();
> + if (ptrace (PTRACE_GETEVENTMSG, event_ptid.lwp (), (PTRACE_TYPE_ARG3) 0,
> + &execing_tid) != 0)
> + execing_tid = event_ptid.lwp ();
This gave me pause -- this is setting execing_tid to the event lwp if ptrace fails.
But execing_tid is already initialized to the event lwp. I think it'd be clearer not
to initialize it, like:
unsigned long execing_tid;
if (ptrace (PTRACE_GETEVENTMSG, event_ptid.lwp (), (PTRACE_TYPE_ARG3) 0,
&execing_tid) != 0)
execing_tid = event_ptid.lwp ();
Otherwise:
Approved-By: Pedro Alves <pedro@palves.net>
Thanks,
Pedro Alves
next prev parent reply other threads:[~2026-06-26 17:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 14:32 simon.marchi
2026-06-26 17:35 ` Pedro Alves [this message]
2026-06-26 18:00 ` Simon Marchi
2026-06-26 18:04 ` Pedro Alves
2026-06-26 18:06 ` Simon Marchi
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=a3dcf9e7-9a4d-4c19-abf5-8d6ba85b2f73@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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