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 v2 1/3] gdb: parameterize all_threads_safe for the target and ptid
Date: Mon, 20 Apr 2026 15:46:09 +0200	[thread overview]
Message-ID: <20260420134611.4009838-1-tankut.baris.aktemur@intel.com> (raw)

'all_threads' and 'all_threads_safe' are two range providers to
iterate over threads.  The former takes optional process target and
ptid arguments to filter the threads that are being iterated.  The
latter does not.  Enhance 'all_threads_safe' to also take the optional
arguments.  Use the new version of the function in two places.
---
 gdb/gdbthread.h   | 5 +++--
 gdb/infrun.c      | 8 ++++----
 gdb/remote.c      | 5 +----
 gdb/thread-iter.h | 2 +-
 4 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 729dcf5ab06..3c568e29a04 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -864,9 +864,10 @@ all_non_exited_threads (process_stratum_target *proc_target = nullptr,
 */
 
 inline all_threads_safe_range
-all_threads_safe ()
+all_threads_safe (process_stratum_target *proc_target = nullptr,
+		  ptid_t filter_ptid = minus_one_ptid)
 {
-  all_threads_iterator begin (all_threads_iterator::begin_t {});
+  all_matching_threads_iterator begin (proc_target, filter_ptid);
   all_threads_safe_iterator safe_begin (std::move (begin));
 
   return all_threads_safe_range (std::move (safe_begin));
diff --git a/gdb/infrun.c b/gdb/infrun.c
index b295956f8ea..46d6b684ebc 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1239,7 +1239,7 @@ static void
 follow_exec (ptid_t ptid, const char *exec_file_target)
 {
   int pid = ptid.pid ();
-  ptid_t process_ptid;
+  ptid_t process_ptid = ptid_t (pid);
 
   /* Switch terminal for any messages produced e.g. by
      breakpoint_re_set.  */
@@ -1285,8 +1285,9 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
      them.  Deleting them now rather than at the next user-visible
      stop provides a nicer sequence of events for user and MI
      notifications.  */
-  for (thread_info &th : all_threads_safe ())
-    if (th.ptid.pid () == pid && th.ptid != ptid)
+  process_stratum_target *target = current_inferior ()->process_target ();
+  for (thread_info &th : all_threads_safe (target, process_ptid))
+    if (th.ptid != ptid)
       delete_thread (&th);
 
   /* We also need to clear any left over stale state for the
@@ -1308,7 +1309,6 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
   update_breakpoints_after_exec ();
 
   /* What is this a.out's name?  */
-  process_ptid = ptid_t (pid);
   gdb_printf (_("%s is executing new program: %s\n"),
 	      target_pid_to_str (process_ptid).c_str (),
 	      exec_file_target);
diff --git a/gdb/remote.c b/gdb/remote.c
index 88668b2748e..7c8aed481f2 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4584,11 +4584,8 @@ remote_target::update_thread_list ()
       /* CONTEXT now holds the current thread list on the remote
 	 target end.  Delete GDB-side threads no longer found on the
 	 target.  */
-      for (thread_info &tp : all_threads_safe ())
+      for (thread_info &tp : all_threads_safe (this))
 	{
-	  if (tp.inf->process_target () != this)
-	    continue;
-
 	  if (!context.contains_thread (tp.ptid))
 	    {
 	      /* Do not remove the thread if it is the last thread in
diff --git a/gdb/thread-iter.h b/gdb/thread-iter.h
index 3c15ada1cbb..32bc6475ebe 100644
--- a/gdb/thread-iter.h
+++ b/gdb/thread-iter.h
@@ -165,7 +165,7 @@ using inf_non_exited_threads_iterator
 /* Iterate over all threads of all inferiors, safely.  */
 
 using all_threads_safe_iterator
-  = basic_safe_iterator<all_threads_iterator>;
+  = basic_safe_iterator<all_matching_threads_iterator>;
 
 /* Iterate over all threads of an inferior, safely.  */
 
-- 
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-20 13:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20 13:46 Tankut Baris Aktemur [this message]
2026-04-20 13:46 ` [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads Tankut Baris Aktemur
2026-04-20 17:02   ` 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-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