From: Tom de Vries <tdevries@suse.de>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] gdb: use inferior::threads instead of all_threads and a PID filter
Date: Fri, 7 Aug 2026 09:59:34 +0200 [thread overview]
Message-ID: <12d8866c-3969-4be2-92af-1fefa28f6373@suse.de> (raw)
In-Reply-To: <2dbabbed902e38a1d4534fd7ecd3362331f71ea8.1786049312.git.aburgess@redhat.com>
On 8/6/26 10:54 PM, Andrew Burgess wrote:
> 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.
Hi Andrew,
this LGTM.
FWIW, I had a Claude Code session review this, and I asked it to find
other locations in need of the same treatment, and it found
sync_threadlists in gdb/aix-thread.c, where we can replace
all_threads_safe with inferior::threads_safe (). But that requires
testing on AIX, so I suppose it's not something that is easily added to
this patch.
Approved-By: Tom de Vries <tdevries@suse.de>
Thanks,
- Tom
> ---
> 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 ())
next prev parent reply other threads:[~2026-08-07 8:00 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 ` [PATCH 1/2] gdb: use inferior::threads instead of all_threads and a PID filter Andrew Burgess
2026-08-07 7:59 ` Tom de Vries [this message]
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=12d8866c-3969-4be2-92af-1fefa28f6373@suse.de \
--to=tdevries@suse.de \
--cc=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