aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2025-08-28 11:10:51 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2025-08-29 16:12:08 -0400
commit02ecff0c714254cd5a67b55a6d11d62cfd904dbc (patch)
treea1eda11fbeb58adc3ae4349f28816e563ce10707
parent1e10e9ea96a4141080a7cd7322babe6bcd7c42ba (diff)
downloadbinutils-02ecff0c714254cd5a67b55a6d11d62cfd904dbc.zip
binutils-02ecff0c714254cd5a67b55a6d11d62cfd904dbc.tar.gz
binutils-02ecff0c714254cd5a67b55a6d11d62cfd904dbc.tar.bz2
gdb/objfiles: use filtered_iterator as objfile::section_iterator
objfile::section_iterator looks like a good candidate to be implemented with filtered_iterator. Following the enhancements to filtered_iterator in the previous patch, it's pretty straighforward. I removed the non-const version of objfile::sections, because it didn't seem useful to have the two methods returning the exact same type and value. Having just the const version achieves the same thing. Change-Id: I2f29c2fb3f95605cb816cc1ff8935c10e0496052 Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/objfiles.h59
1 files changed, 8 insertions, 51 deletions
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index fe7a2ac..2711d4d 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -657,61 +657,18 @@ public:
this->section_offsets[idx] = offset;
}
- class section_iterator
+ /* Filter function for section_iterator. */
+ struct filter_out_null_bfd_section
{
- public:
- section_iterator (const section_iterator &) = default;
- section_iterator (section_iterator &&) = default;
- section_iterator &operator= (const section_iterator &) = default;
- section_iterator &operator= (section_iterator &&) = default;
-
- using self_type = section_iterator;
- using reference = obj_section &;
-
- reference operator* ()
- { return *m_iter; }
-
- section_iterator &operator++ ()
- {
- ++m_iter;
- skip_null ();
- return *this;
- }
-
- bool operator== (const section_iterator &other) const
- { return m_iter == other.m_iter && m_end == other.m_end; }
-
- bool operator!= (const section_iterator &other) const
- { return !(*this == other); }
-
- private:
-
- friend class objfile;
-
- section_iterator (obj_section *iter, obj_section *end)
- : m_iter (iter),
- m_end (end)
- {
- skip_null ();
- }
-
- void skip_null ()
- {
- while (m_iter < m_end && m_iter->the_bfd_section == nullptr)
- ++m_iter;
- }
-
- obj_section *m_iter;
- obj_section *m_end;
+ bool operator() (const obj_section &sec) const noexcept
+ { return sec.the_bfd_section != nullptr; }
};
- iterator_range<section_iterator> sections ()
- {
- return (iterator_range<section_iterator>
- (section_iterator (sections_start, sections_end),
- section_iterator (sections_end, sections_end)));
- }
+ using section_iterator = filtered_iterator<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 () const
{
return (iterator_range<section_iterator>