Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid
@ 2026-04-20 13:46 Tankut Baris Aktemur
  2026-04-20 13:46 ` [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads Tankut Baris Aktemur
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Tankut Baris Aktemur @ 2026-04-20 13:46 UTC (permalink / raw)
  To: gdb-patches

'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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads
  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
  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 16:58 ` [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid Simon Marchi
  2 siblings, 1 reply; 9+ messages in thread
From: Tankut Baris Aktemur @ 2026-04-20 13:46 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 3/3] gdb, multi-target: pass a target argument to delete_exited_threads
  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 ` [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads Tankut Baris Aktemur
@ 2026-04-20 13:46 ` Tankut Baris Aktemur
  2026-04-20 17:20   ` Simon Marchi
  2026-04-20 16:58 ` [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid Simon Marchi
  2 siblings, 1 reply; 9+ messages in thread
From: Tankut Baris Aktemur @ 2026-04-20 13:46 UTC (permalink / raw)
  To: gdb-patches

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     | 6 +++---
 6 files changed, 10 insertions(+), 10 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 fb1969e2f94..07ac231fc84 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -983,9 +983,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 6018d6c9914..d7d5e010748 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3967,7 +3967,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 64c06dc87f6..74124596b28 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -779,9 +779,9 @@ 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 ())
+  for (thread_info &tp : all_threads_safe (target))
     if (tp.state () == THREAD_EXITED)
       delete_thread (&tp);
 }
@@ -2112,7 +2112,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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid
  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 ` [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads Tankut Baris Aktemur
  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 16:58 ` Simon Marchi
  2026-04-20 17:21   ` Aktemur, Tankut Baris
  2 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2026-04-20 16:58 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 4/20/26 9:46 AM, Tankut Baris Aktemur wrote:
> 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);

ptid_t process_ptid (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)

Just noting that this is a behavior change, the previous code iterated
threads of all targets, while the new code only iterates the threads of
the current process target.  You could have passed nullptr to preserve
existing behavior.  But I think this is a good change, it's the same
spirit as your other patches.

> 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;
> -

You could now remove the braces for the `for`, to reduce indentation a
bit.

>  	  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>;

I'd rename all_threads_safe_iterator to
all_matching_threads_safe_iterator, to try to preserve the logic in how
these are named.

all_threads_safe_range would also be renamed to
all_matching_threads_safe_range.

With those fixed:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] gdb, multi-target: pass a target argument to prune_threads
  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
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2026-04-20 17:02 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 4/20/26 9:46 AM, Tankut Baris Aktemur wrote:
> 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);

I think we should not be afraid to use references for things that must
not be nullptr.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] gdb, multi-target: pass a target argument to delete_exited_threads
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2026-04-20 17:20 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 4/20/26 9:46 AM, Tankut Baris Aktemur wrote:
> 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);

Not related to your patch, but I'm a bit curious to know why this
delete_exited_threads is not done when we "mourn" the previous existence
of the inferior.  In the lifecycle of an inferior, there should always
be a point where an inferior stops "being", before "becoming" a new
execution.  At that point, the process target would be known and we
could pass it to delete_exited_threads.

> @@ -2112,7 +2112,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);

I don't know if it's worthwhile, but we could restrict this one to the
process target of the previously selected thread.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Aktemur, Tankut Baris @ 2026-04-20 17:21 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On Monday, April 20, 2026 6:58 PM, Simon Marchi wrote:
> On 4/20/26 9:46 AM, Tankut Baris Aktemur wrote:
> > 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);
> 
> ptid_t process_ptid (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)
> 
> Just noting that this is a behavior change, the previous code iterated
> threads of all targets, while the new code only iterates the threads of
> the current process target.  You could have passed nullptr to preserve
> existing behavior.  But I think this is a good change, it's the same
> spirit as your other patches.

Ack.

> > 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;
> > -
> 
> You could now remove the braces for the `for`, to reduce indentation a
> bit.

There is another loop right after this one where we can apply
the same rule.  Shall I remove braces there, too, in another
obvious patch?  Otherwise, we will have inconsistency within
the function.

> >  	  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>;
> 
> I'd rename all_threads_safe_iterator to
> all_matching_threads_safe_iterator, to try to preserve the logic in how
> these are named.
> 
> all_threads_safe_range would also be renamed to
> all_matching_threads_safe_range.
> 
> With those fixed:
> 
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
> 
> Simon

Thank you.
-Baris

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] gdb: parameterize all_threads_safe for the target and ptid
  2026-04-20 17:21   ` Aktemur, Tankut Baris
@ 2026-04-20 17:49     ` Simon Marchi
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2026-04-20 17:49 UTC (permalink / raw)
  To: Aktemur, Tankut Baris, gdb-patches

On 4/20/26 1:21 PM, Aktemur, Tankut Baris wrote:
> There is another loop right after this one where we can apply
> the same rule.  Shall I remove braces there, too, in another
> obvious patch?  Otherwise, we will have inconsistency within
> the function.

Sure, you can push an obvious patch to fix it.

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH v2 3/3] gdb, multi-target: pass a target argument to delete_exited_threads
  2026-04-20 17:20   ` Simon Marchi
@ 2026-04-21  7:48     ` Aktemur, Tankut Baris
  0 siblings, 0 replies; 9+ messages in thread
From: Aktemur, Tankut Baris @ 2026-04-21  7:48 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On Monday, April 20, 2026 7:21 PM, Simon Marchi wrote:
> On 4/20/26 9:46 AM, Tankut Baris Aktemur wrote:
> > 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);
> 
> Not related to your patch, but I'm a bit curious to know why this
> delete_exited_threads is not done when we "mourn" the previous existence
> of the inferior.  In the lifecycle of an inferior, there should always
> be a point where an inferior stops "being", before "becoming" a new
> execution.  At that point, the process target would be known and we
> could pass it to delete_exited_threads.

Hmm, was it maybe desired to keep the threads around at mourn phase even
in exited state for some user-interface related reason?  I'm not sure.

> > @@ -2112,7 +2112,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);
> 
> I don't know if it's worthwhile, but we could restrict this one to the
> process target of the previously selected thread.

I'm inclined towards preserving the current behavior for this one.
The previous thread and the selected thread can both be from the
same target and both could be exited, meaning they could potentially
be deleted by the call.  If a behavior change is desired, IMHO it
deserves a separate patch -- the behavioral changes in other places
in this series were clear optimizations but the change here would be
more than that, I think.
 
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
> 
> Simon

Thank you.
-Baris

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-04-21  7:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox