From: Tom Tromey <tom@tromey.com>
To: Tom de Vries <tdevries@suse.de>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 08/10] [gdb] Use block::block_and_superblocks
Date: Fri, 08 May 2026 13:41:56 -0600 [thread overview]
Message-ID: <87ik8xn0xn.fsf@tromey.com> (raw)
In-Reply-To: <20260501124504.2233495-9-tdevries@suse.de> (Tom de Vries's message of "Fri, 1 May 2026 14:45:02 +0200")
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> diff --git a/gdb/blockframe.c b/gdb/blockframe.c
Tom> index 8aafa6ffe57..5c981748cbc 100644
Tom> --- a/gdb/blockframe.c
Tom> +++ b/gdb/blockframe.c
Tom> @@ -69,13 +69,14 @@ get_frame_block (const frame_info_ptr &frame, CORE_ADDR *addr_in_block)
Tom> inline_count = frame_inlined_callees (frame);
Tom> - while (inline_count > 0)
Tom> + auto range = bl->block_and_superblocks ();
Tom> + for (auto b = range.begin (); b != range.end (); ++b, bl = *b)
Tom> {
Tom> - if (bl->inlined_p ())
Tom> - inline_count--;
Tom> + if (inline_count <= 0)
Tom> + break;
Tom> - bl = bl->superblock ();
Tom> - gdb_assert (bl != NULL);
Tom> + if ((*b)->inlined_p ())
Tom> + inline_count--;
Tom> }
Tom> return bl;
I think this particular change is less clear than the code it replaces.
Tom> diff --git a/gdb/dwarf2/line-program.c b/gdb/dwarf2/line-program.c
Tom> index b9da1b4799f..227ec01aec9 100644
Tom> --- a/gdb/dwarf2/line-program.c
Tom> +++ b/gdb/dwarf2/line-program.c
Tom> @@ -373,21 +373,15 @@ dwarf_find_and_extend_inline_block_range (dwarf2_cu *cu,
Tom> the child of a non-inline block. This is new inline block is our
Tom> candidate for extending. */
Tom> struct block *block = nullptr;
Tom> - for (const struct block *b = it->second;
Tom> - b != nullptr;
Tom> - b = b->superblock ())
Tom> - {
Tom> - if (b->function () != nullptr && b->inlined_p ())
Tom> - {
Tom> - if (b->superblock () != nullptr
Tom> - && b->superblock ()->function () != nullptr
Tom> - && !b->superblock ()->inlined_p ())
Tom> - {
Tom> - block = const_cast<struct block *> (b);
Tom> - break;
Tom> - }
Tom> - }
Tom> - }
Tom> + for (auto b : block::block_and_superblocks (it->second))
Tom> + if (b->inlined_p ()
Tom> + && b->superblock () != nullptr
Tom> + && b->superblock ()->function () != nullptr
Tom> + && !b->superblock ()->inlined_p ())
Tom> + {
Tom> + block = const_cast<struct block *> (b);
Tom> + break;
Tom> + }
It took me a while to figure out why you removed the check of
'function', but it's because inlined_p already does this check.
It's helpful to call out this kind of change or to put it in a separate
patch.
Tom> --- a/gdb/infrun.c
Tom> +++ b/gdb/infrun.c
Tom> @@ -8261,13 +8261,15 @@ process_event_stop_test (struct execution_control_state *ecs)
Tom> const struct block *prev
Tom> = block_for_pc (ecs->event_thread->control.step_frame_id.code_addr);
Tom> const struct block *curr = block_for_pc (ecs->event_thread->stop_pc ());
Tom> - while (curr != nullptr && !curr->contains (prev))
Tom> + for (auto b : block::block_and_superblocks (curr))
Tom> {
This code would be clearer if 'curr' were eliminated entirely.
In this case I had to go see if it was used after the loop.
Tom> + auto range = block::block_and_superblocks (cur_block);
Tom> + for (auto b = range.begin (); b != range.end (); ++b, cur_block = *b)
This is another case where the result is harder to reason about that the
earlier code.
Maybe it could be salvaged somehow by assigning at the breaks, not sure.
Tom> diff --git a/gdb/symmisc.c b/gdb/symmisc.c
Tom> index 89374bd8a2f..f882f3add17 100644
Tom> --- a/gdb/symmisc.c
Tom> +++ b/gdb/symmisc.c
Tom> @@ -961,11 +961,10 @@ block_depth (const struct block *block)
Tom> {
Tom> int i = 0;
Tom> - while ((block = block->superblock ()) != NULL)
Tom> - {
Tom> - i++;
Tom> - }
Tom> - return i;
Tom> + for (auto b [[maybe_unused]]: block::block_and_superblocks (block))
Tom> + i++;
Tom> +
Tom> + return i - 1;
Can this just be std::count?
Also this doesn't have to handle the case where the initial block is
nullptr.
Tom> + auto range = block::block_and_superblocks (bl);
Tom> + for (auto b = range.begin (); b != range.end (); ++b, bl = *b)
Like the earlier ones. I don't think multiple assignments like this
make it clearer or easier to work with.
Tom
next prev parent reply other threads:[~2026-05-08 19:42 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 ` [PATCH 07/10] [gdb] Add block::block_and_superblocks Tom de Vries
2026-05-01 12:45 ` [PATCH 08/10] [gdb] Use block::block_and_superblocks Tom de Vries
2026-05-08 19:41 ` Tom Tromey [this message]
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=87ik8xn0xn.fsf@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
/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