* [PATCH 1/2] gdb, multi-target: pass a target argument to prune_threads
@ 2026-04-17 11:14 Tankut Baris Aktemur
2026-04-17 15:16 ` Andrew Burgess
0 siblings, 1 reply; 3+ messages in thread
From: Tankut Baris Aktemur @ 2026-04-17 11:14 UTC (permalink / raw)
To: gdb-patches
From the way 'prune_threads' is used, it is designed to delete the
threads of the current target. So, while iterating the threads,
ignore those that do not belong to the current target.
To do this, prune_threads is modified to take a process_stratum_target
as a parameter.
---
gdb/bsd-uthread.c | 2 +-
gdb/fbsd-nat.c | 2 +-
gdb/gdbthread.h | 5 +++--
gdb/gnu-nat.c | 2 +-
gdb/obsd-nat.c | 2 +-
gdb/procfs.c | 2 +-
gdb/remote.c | 2 +-
gdb/sol-thread.c | 2 +-
gdb/thread.c | 7 ++++++-
9 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 0aa8ebda558..64a67cdfb8b 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -454,7 +454,7 @@ bsd_uthread_target::update_thread_list ()
int offset = bsd_uthread_thread_next_offset;
CORE_ADDR addr;
- prune_threads ();
+ prune_threads (current_inferior ()->process_target ());
addr = bsd_uthread_read_memory_address (bsd_uthread_thread_list_addr);
while (addr != 0)
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index 9e7965b900a..a1c7801ec1e 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -1006,7 +1006,7 @@ fbsd_nat_target::update_thread_list ()
list as events are reported, so just try deleting exited threads. */
delete_exited_threads ();
#else
- prune_threads ();
+ prune_threads (this);
fbsd_add_threads (this, inferior_ptid.pid ());
#endif
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index c56c4ce4036..835d07dc660 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -963,9 +963,10 @@ extern struct thread_info* inferior_thread (void);
extern void update_thread_list (void);
-/* Delete any thread the target says is no longer alive. */
+/* Delete any thread of TARGET that the target says is no longer
+ alive. */
-extern void prune_threads (void);
+extern void prune_threads (process_stratum_target *target);
/* Delete threads marked THREAD_EXITED. Unlike prune_threads, this
does not consult the target about whether the thread is alive right
diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c
index 70685cee526..9f481ba7e8b 100644
--- a/gdb/gnu-nat.c
+++ b/gdb/gnu-nat.c
@@ -2146,7 +2146,7 @@ gnu_nat_target::create_inferior (const char *exec_file,
inf->pending_execs = 0;
/* Get rid of the old shell threads. */
- prune_threads ();
+ prune_threads (this);
inf_validate_procinfo (inf);
inf_update_signal_thread (inf);
diff --git a/gdb/obsd-nat.c b/gdb/obsd-nat.c
index e659434a1aa..a32a03bb042 100644
--- a/gdb/obsd-nat.c
+++ b/gdb/obsd-nat.c
@@ -48,7 +48,7 @@ obsd_nat_target::update_thread_list ()
pid_t pid = inferior_ptid.pid ();
struct ptrace_thread_state pts;
- prune_threads ();
+ prune_threads (this);
if (ptrace (PT_GET_THREAD_FIRST, pid, (caddr_t)&pts, sizeof pts) == -1)
perror_with_name (("ptrace"));
diff --git a/gdb/procfs.c b/gdb/procfs.c
index cea9f823bbc..f50d825cfe8 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -2868,7 +2868,7 @@ procfs_target::update_thread_list ()
{
procinfo *pi;
- prune_threads ();
+ prune_threads (this);
/* Find procinfo for main process. */
pi = find_procinfo_or_die (inferior_ptid.pid (), 0);
diff --git a/gdb/remote.c b/gdb/remote.c
index 88668b2748e..3d257fe3ca8 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4651,7 +4651,7 @@ remote_target::update_thread_list ()
each known thread is alive, one by one, with the T packet.
If the target doesn't support threads at all, then this is a
no-op. See remote_thread_alive. */
- prune_threads ();
+ prune_threads (this);
}
}
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index c765a4205a0..0e812c472d4 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -1012,7 +1012,7 @@ void
sol_thread_target::update_thread_list ()
{
/* Delete dead threads. */
- prune_threads ();
+ prune_threads (current_inferior ()->process_target ());
/* Find any new LWP's. */
beneath ()->update_thread_list ();
diff --git a/gdb/thread.c b/gdb/thread.c
index a6ae2a75139..861eca3591d 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -764,12 +764,17 @@ switch_to_thread_if_alive (thread_info *thr)
/* See gdbthreads.h. */
void
-prune_threads (void)
+prune_threads (process_stratum_target *target)
{
+ gdb_assert (target != nullptr);
+
scoped_restore_current_thread restore_thread;
for (thread_info &tp : all_threads_safe ())
{
+ if (tp.inf->process_target () != target)
+ continue;
+
switch_to_inferior_no_thread (tp.inf);
if (!thread_alive (&tp))
--
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] 3+ messages in thread
* Re: [PATCH 1/2] gdb, multi-target: pass a target argument to prune_threads
2026-04-17 11:14 [PATCH 1/2] gdb, multi-target: pass a target argument to prune_threads Tankut Baris Aktemur
@ 2026-04-17 15:16 ` Andrew Burgess
2026-04-17 15:35 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2026-04-17 15:16 UTC (permalink / raw)
To: Tankut Baris Aktemur, gdb-patches
Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> writes:
> From the way 'prune_threads' is used, it is designed to delete the
> threads of the current target. So, while iterating the threads,
> ignore those that do not belong to the current target.
I'm not saying that you're wrong, but could you expand on this, maybe
giving some examples of how it's used and why that suggests it should be
a per- target operation.
Did the current code cause some problems? Is there scope for adding a
test maybe?
FWIW: I think this change is probably OK, but the commit message seems a
little light on detail for my taste.
Thanks,
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] gdb, multi-target: pass a target argument to prune_threads
2026-04-17 15:16 ` Andrew Burgess
@ 2026-04-17 15:35 ` Simon Marchi
0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2026-04-17 15:35 UTC (permalink / raw)
To: Andrew Burgess, Tankut Baris Aktemur, gdb-patches
On 4/17/26 11:16 AM, Andrew Burgess wrote:
> Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> writes:
>
>> From the way 'prune_threads' is used, it is designed to delete the
>> threads of the current target. So, while iterating the threads,
>> ignore those that do not belong to the current target.
>
> I'm not saying that you're wrong, but could you expand on this, maybe
> giving some examples of how it's used and why that suggests it should be
> a per- target operation.
>
> Did the current code cause some problems? Is there scope for adding a
> test maybe?
>
> FWIW: I think this change is probably OK, but the commit message seems a
> little light on detail for my taste.
>
> Thanks,
> Andrew
I'm not against having more details, but the fact that prune_threads is
called from the various targets' update_thread_list methods (or similar)
is a good clue. In a multi-target scenario, as the target updates the
threads it is responsible for, it should not start messing with threads
of other targets.
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-17 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-17 11:14 [PATCH 1/2] gdb, multi-target: pass a target argument to prune_threads Tankut Baris Aktemur
2026-04-17 15:16 ` Andrew Burgess
2026-04-17 15:35 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox