* [PATCH v2] gdb: use correct target in notify_thread_exited()
@ 2026-05-05 7:57 Markus Metzger
2026-05-05 16:20 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Markus Metzger @ 2026-05-05 7:57 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
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);
+
if (exit_code.has_value ())
gdb_printf (_("[%s (id %s) exited with code %s]\n"),
target_pid_to_str (t->ptid).c_str (),
--
2.34.1
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] gdb: use correct target in notify_thread_exited()
2026-05-05 7:57 [PATCH v2] gdb: use correct target in notify_thread_exited() Markus Metzger
@ 2026-05-05 16:20 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2026-05-05 16:20 UTC (permalink / raw)
To: Markus Metzger, gdb-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-05 16:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-05 7:57 [PATCH v2] gdb: use correct target in notify_thread_exited() Markus Metzger
2026-05-05 16:20 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox