From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <pedro@palves.net>, 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 14:00:59 -0400 [thread overview]
Message-ID: <b7a42372-ebec-430e-ba72-32b14d8788f5@polymtl.ca> (raw)
In-Reply-To: <a3dcf9e7-9a4d-4c19-abf5-8d6ba85b2f73@palves.net>
On 2026-06-26 13:35, Pedro Alves wrote:
> 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.
I'll see what I can do. I'd like to have a test to expose this alleged
bug, but it's not easy.
>> + 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 ();
Well, the question then is: what if the ptrace call fails? It probably
never fails, but we still have to think about it. execing_tid would be
used uninitialized. I see three options:
1. Don't carry over any stop_expected, that would degrade to the
behavior we have today.
2. Continue with the leader's id and lwp_info, falling back to carrying
over the leader's stop_expected flag (which may or may not be right,
we don't know which thread actually exec'd)
3. Give up and abandon everything.
My code does #2, which I thought was a useful fallback (since it will be
right most of the time, execs from a multi-threaded program are probably
are, execs from a non-leader thread even more so). But there is the
theoretical risk of carrying over a stop_expected flag that we shouldn't
have, and the user really uses SIGSTOP, and we would erroneously swallow
it.
So it might be safer (and simpler) to do #1, the only risk I see is that
the user might get a spurious SIGSTOP, which is surprising but doesn't
break the debugging session. I would go for that. Let me know what you
think and I'll send a v2.
Simon
next prev parent reply other threads:[~2026-06-26 18:01 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
2026-06-26 18:00 ` Simon Marchi [this message]
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=b7a42372-ebec-430e-ba72-32b14d8788f5@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=pedro@palves.net \
/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