Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/2] gdb: use inferior::threads instead of all_threads and a PID filter
Date: Thu,  6 Aug 2026 21:54:00 +0100	[thread overview]
Message-ID: <2dbabbed902e38a1d4534fd7ecd3362331f71ea8.1786049312.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1786049312.git.aburgess@redhat.com>

I noticed a few places where we iterated over `all_threads ()` but
then immediately filtered by PID.  It would be better to instead
iterate over `inferior::threads ()` and remove the PID filtering.

These should be equivalent as a single inferior should contain every
thread with a given PID, and should only contain threads with that
given PID.

While editing the `for (...)` loops I have replaced 'auto' with
'thread_info' for additional type clarity.

There should be no user visible changes after this commit.
---
 gdb/mi/mi-main.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 8b6da41ffeb..903c6a5f411 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -359,14 +359,11 @@ mi_cmd_exec_interrupt (const char *command, const char *const *argv, int argc)
       scoped_disable_commit_resumed disable_commit_resumed
 	("interrupting all threads of thread group");
 
-      for (auto &thread : all_threads ())
+      for (thread_info &thread : inf->threads ())
 	{
 	  if (thread.state () != THREAD_RUNNING)
 	    continue;
 
-	  if (thread.ptid.pid () != inf->pid)
-	    continue;
-
 	  target_stop (thread.ptid);
 	}
     }
@@ -603,14 +600,13 @@ print_one_inferior (struct inferior *inferior, bool recurse,
 
       if (inferior->pid != 0)
 	{
-	  for (auto &ti : all_threads ())
-	    if (ti.ptid.pid () == inferior->pid)
-	      {
-		int core = target_core_of_thread (ti.ptid);
+	  for (thread_info &ti : inferior->threads ())
+	    {
+	      int core = target_core_of_thread (ti.ptid);
 
-		if (core != -1)
-		  cores.insert (core);
-	      }
+	      if (core != -1)
+		cores.insert (core);
+	    }
 	}
 
       if (!cores.empty ())
-- 
2.25.4


  reply	other threads:[~2026-08-06 20:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 20:53 [PATCH 0/2] Cleanup and bug fix related to thread iteration and proceed calls Andrew Burgess
2026-08-06 20:54 ` Andrew Burgess [this message]
2026-08-07  7:59   ` [PATCH 1/2] gdb: use inferior::threads instead of all_threads and a PID filter Tom de Vries
2026-08-06 20:54 ` [PATCH 2/2] gdb: share some thread proceed related code between CLI and MI Andrew Burgess
2026-08-07  9:20   ` Tom de Vries
2026-08-07 15:40     ` Andrew Burgess
2026-08-07 10:14   ` Tom de Vries
2026-08-07 15:31     ` Andrew Burgess
2026-08-07 16:52       ` Tom de Vries
2026-08-24 18:18         ` Andrew Burgess

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=2dbabbed902e38a1d4534fd7ecd3362331f71ea8.1786049312.git.aburgess@redhat.com \
    --to=aburgess@redhat.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