Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simon.marchi@efficios.com>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: Re: [PATCH 05/11] gdb, gdbserver: split iterate_over_lwps in for_each_lwp and find_lwp
Date: Fri, 17 Apr 2026 12:25:09 +0100	[thread overview]
Message-ID: <87mrz1esmi.fsf@redhat.com> (raw)
In-Reply-To: <20260416202408.422441-6-simon.marchi@efficios.com>

Simon Marchi <simon.marchi@efficios.com> writes:

> From: Simon Marchi <simon.marchi@polymtl.ca>


> Subject: Re: [PATCH 05/11] gdb, gdbserver: split iterate_over_lwps in for_each_lwp and find_lwp

The subject line should say 'into' maybe?

>
> Even though it works, I have always been mildly annoyed by
> iterate_over_lwps being used for both iterating over all lwps and
> finding one lwp matching a criterion.  I think it would be clearer to
> have two functions for the two use cases.  Then it would be 100% clear
> at the call site what the intention is.  It would be clear that a
> callback returning bool is meant to be a predicate for the find
> function, while a callback returning void is meant to be a callback for
> the "for each" function.
>
> Therefore, split iterate_over_lwps in two:
>
>  - find_lwp to find the first lwp matching a boolean predicate (and the
>    given ptid filter)
>  - for_each_lwp to apply a function on all lwps (optionally filtering by
>    ptid or pid)
>
> The callbacks given to for_each_lwp can now return void.
>
> Introduce some overloads for for_each_lwp, for the various common use
> cases:
>
>  - filtering by ptid
>  - filtering by pid
>  - no ptid/pid filter
>
> find_lwp and two overloads of for_each_lwp are actually only used in
> gdb/linux-nat.c, so make them local to that file.  Only the pid variant
> of for_each_lwp is used in shared code.
>
> The pattern used in this patch serves as the basis for subsequent
> patches that split other "iterate over" functions the same way.
>
> Change-Id: I49d3af0916622300cc81e3c32d22e1aff13cf38f
> ---
>  gdb/arm-linux-nat.c                |  38 ++--
>  gdb/linux-nat.c                    | 276 +++++++++++++++--------------
>  gdb/nat/aarch64-linux-hw-point.c   |  17 +-
>  gdb/nat/linux-nat.h                |  16 +-
>  gdb/nat/loongarch-linux-hw-point.c |  18 +-
>  gdb/nat/x86-linux-dregs.c          |  15 +-
>  gdb/ppc-linux-nat.c                |  22 +--
>  gdb/s390-linux-nat.c               |  22 +--
>  gdbserver/linux-low.cc             |  20 +--
>  9 files changed, 208 insertions(+), 236 deletions(-)
>

> @@ -2940,7 +2953,7 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status)
>  
>  /* Return non-zero if LP has been resumed.  */

This comment needs updating now a bool is returned.

>  
> -static int
> +static bool
>  resumed_callback (struct lwp_info *lp)
>  {
>    return lp->resumed;

> diff --git a/gdb/nat/linux-nat.h b/gdb/nat/linux-nat.h
> index 42c0467191fe..4414749b93de 100644
> --- a/gdb/nat/linux-nat.h
> +++ b/gdb/nat/linux-nat.h
> @@ -46,17 +46,15 @@ extern tribool have_ptrace_getregset;
>  
>  extern ptid_t current_lwp_ptid (void);
>  
> -/* Function type for the CALLBACK argument of iterate_over_lwps.  */
> -using iterate_over_lwps_ftype = gdb::function_view<int (lwp_info *lwp)>;
> +/* Function type for the CALLBACK argument of for_each_lwp.  */
>  
> -/* Iterate over all LWPs.  Calls CALLBACK with its second argument set
> -   to DATA for every LWP in the list.  If CALLBACK returns nonzero for
> -   a particular LWP, return a pointer to the structure describing that
> -   LWP immediately.  Otherwise return NULL.  This function must be
> -   provided by the client.  */
> +using for_each_lwp_ftype = gdb::function_view<void (lwp_info *lwp)>;
>  
> -extern lwp_info *iterate_over_lwps (ptid_t filter,
> -				    iterate_over_lwps_ftype callback);
> +/* Iterate over all LWPs, calling CALLBACK for every LWP.
> +
> +   Only consider the LWPs with that pid.  */

Maybe: "Only consider the LWPs that match PID." would be better?

> +
> +extern void for_each_lwp (int pid, for_each_lwp_ftype callback);
>  
>  /* Return the ptid of LWP.  */
>  

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


  reply	other threads:[~2026-04-17 11:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-16 20:16 [PATCH 00/11] Readability improvements of some iteration functions Simon Marchi
2026-04-16 20:16 ` [PATCH 01/11] gdb/dwarf: remove unused file_match parameter from dwarf2_base_index_functions::search_one Simon Marchi
2026-04-17 11:11   ` Andrew Burgess
2026-04-16 20:16 ` [PATCH 02/11] gdb: rename search_symtabs_expansion_listener -> compunit_symtab_iteration_callback Simon Marchi
2026-04-17 15:08   ` Simon Marchi
2026-04-17 17:17   ` Tom Tromey
2026-04-17 19:34     ` Simon Marchi
2026-04-16 20:16 ` [PATCH 03/11] gdb: introduce iteration_status enum, use it for search callbacks Simon Marchi
2026-04-17 11:01   ` Andrew Burgess
2026-04-17 14:33     ` Simon Marchi
2026-04-17 14:34   ` Tom Tromey
2026-04-16 20:16 ` [PATCH 04/11] gdb, gdbserver: make iterate_over_lwps_ftype a function_view Simon Marchi
2026-04-17 11:09   ` Andrew Burgess
2026-04-17 14:37     ` Simon Marchi
2026-04-16 20:16 ` [PATCH 05/11] gdb, gdbserver: split iterate_over_lwps in for_each_lwp and find_lwp Simon Marchi
2026-04-17 11:25   ` Andrew Burgess [this message]
2026-04-17 14:53     ` Simon Marchi
2026-04-16 20:16 ` [PATCH 06/11] gdb: split iterate_over_threads in for_each_thread and find_thread Simon Marchi
2026-04-17 11:33   ` Andrew Burgess
2026-04-16 20:16 ` [PATCH 07/11] gdb: split iterate_over_minimal_symbols in for_each_minimal_symbol and find_minimal_symbol Simon Marchi
2026-04-17 12:13   ` Andrew Burgess
2026-04-16 20:16 ` [PATCH 08/11] gdb: split iterate_over_symtabs in for_each_symtab and find_symtab Simon Marchi
2026-04-17 13:31   ` Andrew Burgess
2026-04-17 14:54     ` Simon Marchi
2026-04-16 20:16 ` [PATCH 09/11] gdb: change objfile::map_symtabs_matching_filename to find_symtab_matching_filename Simon Marchi
2026-04-17 13:50   ` Andrew Burgess
2026-04-17 15:03     ` Simon Marchi
2026-04-16 20:16 ` [PATCH 10/11] gdb: make symbol_found_callback_ftype a function_view Simon Marchi
2026-04-17 13:55   ` Andrew Burgess
2026-04-17 15:04     ` Simon Marchi
2026-04-16 20:16 ` [PATCH 11/11] gdb: make iterate_over_symbols return void, rename to for_each_symbol Simon Marchi
2026-04-17 14:05   ` Andrew Burgess
2026-04-17 15:06     ` 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=87mrz1esmi.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /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