From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads
Date: Mon, 20 Apr 2026 15:46:10 +0200 [thread overview]
Message-ID: <20260420134611.4009838-2-tankut.baris.aktemur@intel.com> (raw)
In-Reply-To: <20260420134611.4009838-1-tankut.baris.aktemur@intel.com>
The 'prune_threads' function is used by various targets; in one case
in the 'create_inferior' method, in all other cases in
'update_thread_list'. This is an indication that the function should
handle the threads that belong to the calling target and not mess with
the threads of other targets. 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 | 6 ++++--
9 files changed, 14 insertions(+), 11 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 3c568e29a04..fb1969e2f94 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -977,9 +977,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 a208393da07..7472c10616e 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 7c8aed481f2..82a775a4fbb 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4648,7 +4648,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 b5a68b9e46c..dc693c1854d 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 b47479b12e8..64c06dc87f6 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -761,11 +761,13 @@ 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 ())
+ for (thread_info &tp : all_threads_safe (target))
{
switch_to_inferior_no_thread (tp.inf);
--
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
next prev parent reply other threads:[~2026-04-20 13:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 13:46 [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid Tankut Baris Aktemur
2026-04-20 13:46 ` Tankut Baris Aktemur [this message]
2026-04-20 17:02 ` [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads Simon Marchi
2026-04-20 13:46 ` [PATCH v2 3/3] gdb, multi-target: pass a target argument to delete_exited_threads Tankut Baris Aktemur
2026-04-20 17:20 ` Simon Marchi
2026-04-21 7:48 ` Aktemur, Tankut Baris
2026-04-20 16:58 ` [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid Simon Marchi
2026-04-20 17:21 ` Aktemur, Tankut Baris
2026-04-20 17:49 ` 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=20260420134611.4009838-2-tankut.baris.aktemur@intel.com \
--to=tankut.baris.aktemur@intel.com \
--cc=gdb-patches@sourceware.org \
/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