[binutils-gdb] gdb, multi-target: pass a target argument to prune_threads

Tankut Baris Aktemur via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=076b1325895bca26285977cec5200361a1f82aa5

commit 076b1325895bca26285977cec5200361a1f82aa5
Author: Tankut Baris Aktemur <[email protected]>
Date:   Tue Apr 21 09:11:02 2026 +0200

    gdb, multi-target: pass a target argument to prune_threads
    
    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.
    
    Approved-By: Simon Marchi <[email protected]>

Diff:
---
 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 bfafcd61e80..1e3b42265aa 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 442920f02ae..c67ef5de344 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4646,7 +4646,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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.