Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Markus Metzger <markus.t.metzger@intel.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v2] gdb: use correct target in notify_thread_exited()
Date: Tue, 5 May 2026 12:20:05 -0400	[thread overview]
Message-ID: <294bd07f-7d35-4209-a511-9b683b66f2ea@simark.ca> (raw)
In-Reply-To: <20260505075744.936344-1-markus.t.metzger@intel.com>



On 2026-05-05 03:57, Markus Metzger wrote:
> clean_up_just_stopped_threads_fsms() may call notify_thread_exited() in
> the context of a thread from a different target.
> 
> Switch to the thread we're notifying about to get the inferior and target
> right.
> 
> CC: Simon Marchi <simark@simark.ca>
> ---
>  gdb/thread.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/gdb/thread.c b/gdb/thread.c
> index c156f16377b..02ea62d524c 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -203,6 +203,9 @@ notify_thread_exited (thread_info *t, std::optional<ULONGEST> exit_code,
>  {
>    if (!silent && print_thread_events)
>      {
> +      scoped_restore_current_thread restore_thread;
> +      switch_to_thread (t);

Let's use:

  /* Switch inferior before the target calls below.  */
  auto restore_inf = maybe_switch_inferior (t->inf);


> +
>        if (exit_code.has_value ())
>  	gdb_printf (_("[%s (id %s) exited with code %s]\n"),
>  		    target_pid_to_str (t->ptid).c_str (),

I checked if any callee of the observable cared whether THREAD is the
current thread, or if THREAD's inferior is the current inferior, and I
don't think so.  remove_threaded_breakpoints recurses into a bunch of
breakpoint functions so it's difficult to be sure, but at first glance
it seems fine.

With the above fixed:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

      reply	other threads:[~2026-05-05 16:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05  7:57 Markus Metzger
2026-05-05 16:20 ` Simon Marchi [this message]

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=294bd07f-7d35-4209-a511-9b683b66f2ea@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.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