Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] gdb, multi-target: pass a target argument to prune_threads
Date: Fri, 17 Apr 2026 13:14:30 +0200	[thread overview]
Message-ID: <20260417111430.4111679-1-tankut.baris.aktemur@intel.com> (raw)

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


             reply	other threads:[~2026-04-17 11:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17 11:14 Tankut Baris Aktemur [this message]
2026-04-17 15:16 ` Andrew Burgess
2026-04-17 15:35   ` 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=20260417111430.4111679-1-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