Re: [PATCH] gdb: add gdb_bfd_all_sections for range-based iteration

Simon Marchi
2020-08-24T20:34:57Z

On 2020-08-24 4:31 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Simon> I wanted to make a nicer / type-safe interface for
> Simon> bfd_map_over_sections, avoiding the `void *` data parameter.
>
> Simon> My first shot was to make a wrapper for bfd_map_over_sections,
> Simon> gdb_bfd_map_over_sections that took a gdb::function_view.
>
> Simon> However, I think that a range adapter gives nicer and simpler code, as a
> Simon> simple for loop is easier to read than a callback / lambda function. So
> Simon> here it is, it uses next_iterator and next_adapter, so it's not much
> Simon> code.
>
> Simon> As an example, I ported maintenance_info_sections and friends to use it.
> Simon> The maint_print_section_data type could probably be removed now, but I
> Simon> didn't want to do too much in one patch.
>
> I also did this kind of thing -- I have some patches to remove many uses
> of bfd_map_over_sections, though not all of them, since some seem hard
> to test.

What approach did you take?

Simon