From: Simon Marchi <simark@simark.ca>
To: Andrew Burgess <aburgess@redhat.com>,
Simon Marchi <simon.marchi@efficios.com>,
gdb-patches@sourceware.org
Subject: Re: [PATCH 03/11] gdb: introduce iteration_status enum, use it for search callbacks
Date: Fri, 17 Apr 2026 10:33:30 -0400 [thread overview]
Message-ID: <3c340461-f647-42f2-b768-5abd6c11062f@simark.ca> (raw)
In-Reply-To: <87wly5etpa.fsf@redhat.com>
On 4/17/26 7:01 AM, Andrew Burgess wrote:
> Simon Marchi <simon.marchi@efficios.com> writes:
>
>> There are a bunch of iteration functions that take a callback returning
>> true or false to indicate whether to continue or stop iterating. These
>> functions then return the same value, indicate whether the iteration was
>> done until the end of interrupted. I think this is confusing and
>> error-prone, as I never know which value means what. It is especially
>> confusing when two opposite conventions collide, such as in
>> objfile::map_symtabs_matching_filename.
>>
>> I propose to make that more obvious by introducing a new
>> iteration_status enum with self-documenting values.
>>
>> I started to change the callback type
>> compunit_symtab_iteration_callback, taken by
>> quick_symbol_functions::search, and then followed that path to update a
>> bunch of other functions.
>>
>> I chose the name to be kind of generic, so that it can be used for other
>> similar iteration patterns. I also put it in gdbsupport, in case we
>> want to use it in gdbserver too.
>>
>> Change-Id: I55d84d0c1af8ac0b82cc9f49ccf0d6b60e1769e0
>
>
>> @@ -260,30 +259,37 @@ objfile::map_symtabs_matching_filename
>> /* Skip included compunits, as they are searched by
>> iterate_over_one_compunit_symtab. */
>> if (symtab->user != nullptr)
>> - return true;
>> + return iteration_status::keep_going;
>>
>> - /* CALLBACK returns false to keep going and true to continue, so
>> - we have to invert the result here, for search. */
>> - return !iterate_over_one_compunit_symtab (name_basename, name, real_path,
>> - symtab, callback);
>> + /* iterate_over_one_compunit_symtab returns true to stop,
>> + convert to iteration_status. */
>> + if (iterate_over_one_compunit_symtab (name_basename, name, real_path,
>> + symtab, callback)
>> + == iteration_status::stop)
>> + return iteration_status::stop;
>> +
>> + return iteration_status::keep_going;
>
> I think this needs fixing. You've updated
> iterate_over_one_compunit_symtab to return an iteration_status, so I
> think you can just do:
>
> return iterate_over_one_compunit_symtab (name_basename, name, real_path,
> symtab, callback);
>
>
>> };
Ah, of course. I initially did not convert
iterate_over_one_compunit_symtab, which is why I had to have the if to
convert from boolean to iteration_status. I then decided to convert
iterate_over_one_compunit_symtab too, while at it, and left the if in.
>> diff --git a/gdb/symtab.h b/gdb/symtab.h
>> index 0db85bcf5baa..9e45f087adda 100644
>> --- a/gdb/symtab.h
>> +++ b/gdb/symtab.h
>> @@ -30,6 +30,7 @@
>> #include "gdbsupport/gdb_regex.h"
>> #include "gdbsupport/enum-flags.h"
>> #include "gdbsupport/function-view.h"
>> +#include "gdbsupport/iteration-status.h"
>> #include <optional>
>> #include <string_view>
>> #include "gdbsupport/next-iterator.h"
>> @@ -2795,8 +2796,9 @@ bool compare_filenames_for_search (const char *filename,
>> Call CALLBACK with each symtab that is found. If CALLBACK returns
>> true, the search stops. */
>
> This comment that's just peeking in here, needs to be updated. CALLBACK
> no longer returns a bool.
Thanks, fixed.
The comment also talks about psymtabs, which is stale, but that gets
removed in a subsequent commit IIRC.
>> -void iterate_over_symtabs (program_space *pspace, const char *name,
>> - gdb::function_view<bool (symtab *)> callback);
>> +void iterate_over_symtabs
>> + (program_space *pspace, const char *name,
>> + gdb::function_view<iteration_status (symtab *)> callback);
>
> With these fixed, looks good.
>
> Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks, all fixed locally for now.
Simon
next prev parent reply other threads:[~2026-04-17 14:34 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 [this message]
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
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=3c340461-f647-42f2-b768-5abd6c11062f@simark.ca \
--to=simark@simark.ca \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/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