From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 07/10] [gdb] Add block::block_and_superblocks
Date: Fri, 1 May 2026 14:45:01 +0200 [thread overview]
Message-ID: <20260501124504.2233495-8-tdevries@suse.de> (raw)
In-Reply-To: <20260501124504.2233495-1-tdevries@suse.de>
Add a function block::block_and_superblocks that can be used to transform:
...
while (block != NULL)
{
...
block = block->superblock ();
}
...
into:
...
for (auto b : block::block_and_superblocks (block))
{
...
}
...
---
gdb/block.h | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/gdb/block.h b/gdb/block.h
index b70b27f6509..ff5203ae4c6 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -108,6 +108,27 @@ struct blockranges
struct block : public allocate_on_obstack<block>
{
+ /* Variant of next_iterator using the superblock field instead of next. */
+ struct superblock_iterator
+ : base_next_iterator<const block, superblock_iterator>
+ {
+ typedef superblock_iterator self_type;
+
+ explicit superblock_iterator (value_type item)
+ : base_next_iterator (item)
+ {
+ }
+
+ superblock_iterator () = default;
+
+ value_type next ()
+ {
+ return m_item->superblock ();
+ }
+ };
+
+ using superblock_range = iterator_range<superblock_iterator>;
+
/* Return this block's start address. */
CORE_ADDR start () const
{ return m_start; }
@@ -311,6 +332,26 @@ struct block : public allocate_on_obstack<block>
struct dynamic_prop *static_link () const;
+ /* Return a range adapter that iterates over this block and its
+ superblocks. */
+
+ superblock_range block_and_superblocks () const
+ {
+ superblock_range::iterator begin (this);
+
+ return superblock_range (std::move (begin));
+ }
+
+ /* Return a range adapter that iterates over B and its superblocks. */
+
+ static superblock_range block_and_superblocks (const block *b)
+ {
+ if (b == nullptr)
+ return superblock_range ();
+
+ return b->block_and_superblocks ();
+ }
+
/* Return true if block A is lexically nested within this block, or
if A and this block have the same pc range. Return false
otherwise. If ALLOW_NESTED is true, then block A is considered
--
2.51.0
next prev parent reply other threads:[~2026-05-01 12:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 12:44 [PATCH 00/10] [gdb] Add superblocks range loops Tom de Vries
2026-05-01 12:44 ` [PATCH 01/10] [gdb] Use block::containing_function Tom de Vries
2026-05-01 12:44 ` [PATCH 02/10] [gdb] Factor out block::containing_function_block Tom de Vries
2026-05-01 12:44 ` [PATCH 03/10] [gdb] Use block::containing_function_block Tom de Vries
2026-05-01 12:44 ` [PATCH 04/10] [gdb] Add unit test for next_iterator Tom de Vries
2026-05-01 12:44 ` [PATCH 05/10] [gdbsupport] Use using instead of typedef in next_iterator Tom de Vries
2026-05-01 12:45 ` [PATCH 06/10] [gdbsupport] Factor out base_next_iterator Tom de Vries
2026-05-08 19:17 ` Tom Tromey
2026-05-01 12:45 ` Tom de Vries [this message]
2026-05-01 12:45 ` [PATCH 08/10] [gdb] Use block::block_and_superblocks Tom de Vries
2026-05-08 19:41 ` Tom Tromey
2026-05-01 12:45 ` [PATCH 09/10] [gdb] Add block::block_and_superblocks_in_fn Tom de Vries
2026-05-01 12:45 ` [PATCH 10/10] [gdb] Use block::block_and_superblocks_in_fn Tom de Vries
2026-06-09 12:40 ` [PATCH 00/10] [gdb] Add superblocks range loops Tom de Vries
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=20260501124504.2233495-8-tdevries@suse.de \
--to=tdevries@suse.de \
--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