[00/10] Add superblocks range loops

Message ID 20260501124504.2233495-1-tdevries@suse.de
Headers
Series Add superblocks range loops |

Message

Tom de Vries May 1, 2026, 12:44 p.m. UTC
  This series attempts to rewrite code like this:
...
  while (block != NULL)
    {
      ...
      block = block->superblock ();
    }
...
using range loops.

I haven't rewritten loops in block.c itself.

An RFC was submitted here [1].

Changes in v1:
- commit first two patches of RFC
- add a patch adding uses of block::containing_function
- add patches adding and using block::containing_function_block
- add next_iterator unit test, also excercising incomplete type case
- modernize next_iterator by replacing typedef with using
- rewrite base_next_iterator to use Curiously Recurring Template Pattern
- use using to import constructors in next_iterator
- move comment part showing "using a pointer-to-member template argument
  T::next" to commit message
- change names to block_and_superblocks block_and_superblocks_in_fn
- add some missing comments
- complete the refactoring using the range loops
- clarify behaviour of block_and_superblocks_in_fn in relation to static and
  global blocks in commit message
- also avoid static and global blocks in function_block_iterator::next

[1] https://sourceware.org/pipermail/gdb-patches/2026-April/226720.html

Tom de Vries (10):
  [gdb] Use block::containing_function
  [gdb] Factor out block::containing_function_block
  [gdb] Use block::containing_function_block
  [gdb] Add unit test for next_iterator
  [gdbsupport] Use using instead of typedef in next_iterator
  [gdbsupport] Factor out base_next_iterator
  [gdb] Add block::block_and_superblocks
  [gdb] Use block::block_and_superblocks
  [gdb] Add block::block_and_superblocks_in_fn
  [gdb] Use block::block_and_superblocks_in_fn

 gdb/Makefile.in                         |   1 +
 gdb/ada-lang.c                          |  61 ++++------
 gdb/block.c                             |  18 ++-
 gdb/block.h                             | 102 ++++++++++++++++
 gdb/blockframe.c                        |  11 +-
 gdb/compile/compile-c-symbols.c         |  10 +-
 gdb/compile/compile-object-load.c       |   8 +-
 gdb/cp-namespace.c                      |   6 +-
 gdb/cp-support.c                        |   8 +-
 gdb/d-namespace.c                       |   6 +-
 gdb/dwarf2/line-program.c               |  24 ++--
 gdb/f-valprint.c                        |  19 ++-
 gdb/go-lang.c                           |  31 ++---
 gdb/guile/scm-frame.c                   |  13 +-
 gdb/infrun.c                            |  10 +-
 gdb/inline-frame.c                      |  45 ++++---
 gdb/linespec.c                          |  22 ++--
 gdb/mi/mi-cmd-stack.c                   | 155 +++++++++++-------------
 gdb/python/py-frame.c                   |  13 +-
 gdb/python/py-unwind.c                  |  15 +--
 gdb/stack.c                             |  15 +--
 gdb/symmisc.c                           |   9 +-
 gdb/symtab.c                            |  69 ++++++-----
 gdb/tracepoint.c                        |   9 +-
 gdb/unittests/next-iterator-selftests.c | 105 ++++++++++++++++
 gdbsupport/next-iterator.h              |  48 +++++---
 gdbsupport/safe-iterator.h              |  12 +-
 27 files changed, 511 insertions(+), 334 deletions(-)
 create mode 100644 gdb/unittests/next-iterator-selftests.c


base-commit: 27d21139e356aca4b77d32e81105c465f1e6650c
  

Comments

Tom de Vries June 9, 2026, 12:40 p.m. UTC | #1
On 5/1/26 2:44 PM, Tom de Vries wrote:
>    [gdb] Add unit test for next_iterator
>    [gdbsupport] Use using instead of typedef in next_iterator

I've committed these two patches.

I had Claude Code review these, and it complained about a magic constant 
in the unit test, so I eliminated this.  The change is so trivial that 
it doesn't look worth the trouble of re-posting the patch.

Thanks,
- Tom