Re: [PATCH 3/3] gdb/objfiles: use filtered_iterator as objfile::section_iterator

Simon Marchi
2025-08-29T20:23:21Z

On 2025-08-29 12:06, Simon Marchi wrote:
>> Anyway if it didn't then that's just some pre-existing bug, probably not
>> too important.
>
> I'll see if I can make it right, while at it, but otherwise I don't
> think it's a big deal. Not that it's good, but it's not like we are
> anywhere near to have const-correctness in GDB (yet).

I tried to have:

using section_iterator = filtered_iterator<obj_section *, filter_out_null_bfd_section>;
using const_section_iterator
= filtered_iterator<const obj_section *, filter_out_null_bfd_section>;

/* Return an iterable that yields the "non-null" sections of this objfile.
That is, the sections for which obj_section::the_bfd_section is
non-nullptr. */
iterator_range<section_iterator> sections ()
{
return (iterator_range<section_iterator>
(section_iterator (sections_start, sections_end),
section_iterator (sections_end, sections_end)));
}

iterator_range<const_section_iterator> sections () const
{
return (iterator_range<const_section_iterator>
(const_section_iterator (sections_start, sections_end),
const_section_iterator (sections_end, sections_end)));
}

But it would require some changes that extend past the scope of this
patch. Given that this patch doesn't make things worse than they
already are, I'll push my original patch.

Thanks,

Simon