From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] gdb, multi-target: pass a target argument to delete_exited_threads
Date: Fri, 17 Apr 2026 13:14:55 +0200 [thread overview]
Message-ID: <20260417111455.4126998-1-tankut.baris.aktemur@intel.com> (raw)
Similar to the parent commit, delete_exited_threads is also mostly
used in the context of a particular target. Pass that target as a
parameter and skip other targets.
There seems to be two cases where we actually would want to iterate
all targets. One use is in inferior_appeared (inferior.c) and the
other is in thread_select (thread.c). To handle these cases, allow
the argument to be nullptr.
---
gdb/fbsd-nat.c | 2 +-
gdb/gdbthread.h | 6 +++---
gdb/inferior.c | 2 +-
gdb/linux-nat.c | 2 +-
gdb/netbsd-nat.c | 2 +-
gdb/thread.c | 14 ++++++++++----
6 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index a1c7801ec1e..706d6efd342 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -1004,7 +1004,7 @@ fbsd_nat_target::update_thread_list ()
#ifdef PT_LWP_EVENTS
/* With support for thread events, threads are added/deleted from the
list as events are reported, so just try deleting exited threads. */
- delete_exited_threads ();
+ delete_exited_threads (this);
#else
prune_threads (this);
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 835d07dc660..3bd9598907d 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -969,9 +969,9 @@ extern void update_thread_list (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
- now. */
-extern void delete_exited_threads (void);
+ does not consult TARGET about whether the thread is alive right
+ now. If TARGET is nullptr, operate on all targets. */
+extern void delete_exited_threads (process_stratum_target *target);
/* Return true if PC is in the stepping range of THREAD. */
diff --git a/gdb/inferior.c b/gdb/inferior.c
index e050dec402e..1481f46cdd1 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -368,7 +368,7 @@ inferior_appeared (struct inferior *inf, int pid)
{
/* If this is the first inferior with threads, reset the global
thread id. */
- delete_exited_threads ();
+ delete_exited_threads (nullptr);
if (!any_thread_p ())
init_thread_list ();
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index f141ba19ea4..5ac61316445 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3963,7 +3963,7 @@ linux_nat_target::update_thread_list ()
/* We add/delete threads from the list as clone/exit events are
processed, so just try deleting exited threads still in the
thread list. */
- delete_exited_threads ();
+ delete_exited_threads (this);
/* Update the processor core that each lwp/thread was last seen
running on. */
diff --git a/gdb/netbsd-nat.c b/gdb/netbsd-nat.c
index 6b9029bf0ef..36bd91f968c 100644
--- a/gdb/netbsd-nat.c
+++ b/gdb/netbsd-nat.c
@@ -155,7 +155,7 @@ nbsd_nat_target::post_attach (int pid)
void
nbsd_nat_target::update_thread_list ()
{
- delete_exited_threads ();
+ delete_exited_threads (this);
}
/* Convert PTID to a string. */
diff --git a/gdb/thread.c b/gdb/thread.c
index 861eca3591d..4e1f1ad17ac 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -785,11 +785,17 @@ prune_threads (process_stratum_target *target)
/* See gdbthreads.h. */
void
-delete_exited_threads (void)
+delete_exited_threads (process_stratum_target *target)
{
for (thread_info &tp : all_threads_safe ())
- if (tp.state () == THREAD_EXITED)
- delete_thread (&tp);
+ {
+ if (target != nullptr
+ && tp.inf->process_target () != target)
+ continue;
+
+ if (tp.state () == THREAD_EXITED)
+ delete_thread (&tp);
+ }
}
/* Return true value if stack temporaries are enabled for the thread
@@ -2118,7 +2124,7 @@ thread_select (const char *tidstr, thread_info *tp)
/* Since the current thread may have changed, see if there is any
exited thread we can now delete. */
- delete_exited_threads ();
+ delete_exited_threads (nullptr);
}
/* Print thread and frame switch command response. */
--
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 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:20 ` Andrew Burgess
2026-04-17 15:39 ` 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=20260417111455.4126998-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