From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 3/3] gdb/objfiles: use filtered_iterator as objfile::section_iterator
Date: Thu, 28 Aug 2025 11:10:51 -0400 [thread overview]
Message-ID: <20250828151100.84594-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20250828151100.84594-1-simon.marchi@efficios.com>
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
---
gdb/objfiles.h | 59 +++++++-------------------------------------------
1 file changed, 8 insertions(+), 51 deletions(-)
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index fe7a2ac91fda..2711d4dcb06f 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -657,61 +657,18 @@ struct objfile : intrusive_list_node<objfile>
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>
--
2.51.0
next prev parent reply other threads:[~2025-08-28 15:11 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 15:10 [PATCH 1/3] gdb/objfiles: make objfile::sections yield references Simon Marchi
2025-08-28 15:10 ` [PATCH 2/3] gdbsupport: make filtered_iterator work with pointers Simon Marchi
2025-08-29 13:40 ` Tom Tromey
2025-08-29 16:00 ` Simon Marchi
2025-08-29 17:39 ` Tom Tromey
2025-08-29 20:11 ` Simon Marchi
2025-09-03 2:01 ` Tom Tromey
2025-08-29 17:59 ` Simon Marchi
2025-08-29 18:19 ` Tom Tromey
2025-08-28 15:10 ` Simon Marchi [this message]
2025-08-29 13:42 ` [PATCH 3/3] gdb/objfiles: use filtered_iterator as objfile::section_iterator Tom Tromey
2025-08-29 16:06 ` Simon Marchi
2025-08-29 20:22 ` Simon Marchi
2025-08-29 13:34 ` [PATCH 1/3] gdb/objfiles: make objfile::sections yield references Tom Tromey
2025-08-29 15:47 ` 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=20250828151100.84594-3-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
/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