Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 10/10] [gdb] Use block::block_and_superblocks_in_fn
Date: Fri,  1 May 2026 14:45:04 +0200	[thread overview]
Message-ID: <20260501124504.2233495-11-tdevries@suse.de> (raw)
In-Reply-To: <20260501124504.2233495-1-tdevries@suse.de>

Add uses of block::block_and_superblocks_in_fn.
---
 gdb/ada-lang.c                  |  43 ++++-----
 gdb/compile/compile-c-symbols.c |  10 +--
 gdb/f-valprint.c                |  19 ++--
 gdb/mi/mi-cmd-stack.c           | 155 +++++++++++++++-----------------
 gdb/python/py-unwind.c          |   2 +-
 gdb/stack.c                     |  15 ++--
 gdb/symtab.c                    |  11 +--
 gdb/tracepoint.c                |   9 +-
 8 files changed, 114 insertions(+), 150 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 6eb928b445d..400760be1ba 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13118,32 +13118,27 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
 			       const frame_info_ptr &frame,
 			       std::vector<ada_exc_info> *exceptions)
 {
-  const struct block *block = get_frame_block (frame, 0);
+  const struct block *frame_block = get_frame_block (frame, 0);
 
-  while (block != 0)
-    {
-      for (struct symbol *sym : block_iterator_range (block))
-	{
-	  switch (sym->loc_class ())
-	    {
-	    case LOC_TYPEDEF:
-	    case LOC_BLOCK:
-	    case LOC_CONST:
-	      break;
-	    default:
-	      if (ada_is_exception_sym (sym))
-		{
-		  struct ada_exc_info info = {sym->print_name (),
-					      sym->value_address ()};
+  for (auto block : block::block_and_superblocks_in_fn (frame_block))
+    for (struct symbol *sym : block_iterator_range (block))
+      {
+	switch (sym->loc_class ())
+	  {
+	  case LOC_TYPEDEF:
+	  case LOC_BLOCK:
+	  case LOC_CONST:
+	    break;
+	  default:
+	    if (ada_is_exception_sym (sym))
+	      {
+		struct ada_exc_info info = {sym->print_name (),
+					    sym->value_address ()};
 
-		  exceptions->push_back (info);
-		}
-	    }
-	}
-      if (block->function () != NULL)
-	break;
-      block = block->superblock ();
-    }
+		exceptions->push_back (info);
+	      }
+	  }
+      }
 }
 
 /* Add all exceptions defined globally whose name name match
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index dc0487d8f82..da8c6719fe5 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -588,20 +588,14 @@ generate_c_for_variable_locations (compile_instance *compiler,
      reality of shadowing.  */
   gdb::unordered_set<std::string_view> symset;
 
-  while (1)
+  for (auto b : block->block_and_superblocks_in_fn ())
     {
       /* Iterate over symbols in this block, generating code to
 	 compute the location of each local variable.  */
-      for (struct symbol *sym : block_iterator_range (block))
+      for (struct symbol *sym : block_iterator_range (b))
 	if (symset.insert (sym->natural_name ()).second)
 	  generate_c_for_for_one_variable (compiler, stream, gdbarch,
 					   registers_used, pc, sym);
-
-      /* If we just finished the outermost block of a function, we're
-	 done.  */
-      if (block->function () != NULL)
-	break;
-      block = block->superblock ();
     }
 
   return registers_used;
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 13921c03a48..44b24d788d3 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -682,7 +682,7 @@ static void
 info_common_command (const char *comname, int from_tty)
 {
   frame_info_ptr fi;
-  const struct block *block;
+  const struct block *frame_block;
   int values_printed = 0;
 
   /* We have been told to display the contents of F77 COMMON
@@ -695,22 +695,17 @@ info_common_command (const char *comname, int from_tty)
   /* The following is generally ripped off from stack.c's routine
      print_frame_info().  */
 
-  block = get_frame_block (fi, 0);
-  if (block == NULL)
+  frame_block = get_frame_block (fi, 0);
+  if (frame_block == nullptr)
     {
       gdb_printf (_("No symbol table info available.\n"));
       return;
     }
 
-  while (block)
-    {
-      info_common_command_for_block (block, comname, &values_printed);
-      /* After handling the function's top-level block, stop.  Don't
-	 continue to its superblock, the block of per-file symbols.  */
-      if (block->function ())
-	break;
-      block = block->superblock ();
-    }
+  /* After handling the function's top-level block, stop.  Don't
+     continue to its superblock, the block of per-file symbols.  */
+  for (auto block : block::block_and_superblocks_in_fn (frame_block))
+    info_common_command_for_block (block, comname, &values_printed);
 
   if (!values_printed)
     {
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index f2a4b3044b0..0f46033c9b4 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -573,11 +573,11 @@ list_args_or_locals (const frame_print_options &fp_opts,
 		     enum what_to_list what, enum print_values values,
 		     const frame_info_ptr &fi, int skip_unavailable)
 {
-  const struct block *block;
+  const struct block *frame_block;
   const char *name_of_result;
   struct ui_out *uiout = current_uiout;
 
-  block = get_frame_block (fi, 0);
+  frame_block = get_frame_block (fi, 0);
 
   switch (what)
     {
@@ -596,88 +596,81 @@ list_args_or_locals (const frame_print_options &fp_opts,
 
   ui_out_emit_list list_emitter (uiout, name_of_result);
 
-  while (block != 0)
-    {
-      for (struct symbol *sym : block_iterator_range (block))
-	{
-	  int print_me = 0;
-
-	  switch (sym->loc_class ())
-	    {
-	    default:
-	    case LOC_UNDEF:	/* catches errors        */
-	    case LOC_CONST:	/* constant              */
-	    case LOC_TYPEDEF:	/* local typedef         */
-	    case LOC_LABEL:	/* local label           */
-	    case LOC_BLOCK:	/* local function        */
-	    case LOC_CONST_BYTES:	/* loc. byte seq.        */
-	    case LOC_UNRESOLVED:	/* unresolved static     */
-	    case LOC_OPTIMIZED_OUT:	/* optimized out         */
-	      print_me = 0;
-	      break;
+  for (auto block : block::block_and_superblocks_in_fn (frame_block))
+    for (struct symbol *sym : block_iterator_range (block))
+      {
+	int print_me = 0;
+
+	switch (sym->loc_class ())
+	  {
+	  default:
+	  case LOC_UNDEF:		/* catches errors	 */
+	  case LOC_CONST:		/* constant		 */
+	  case LOC_TYPEDEF:		/* local typedef	 */
+	  case LOC_LABEL:		/* local label		 */
+	  case LOC_BLOCK:		/* local function	 */
+	  case LOC_CONST_BYTES:		/* loc. byte seq.	 */
+	  case LOC_UNRESOLVED:		/* unresolved static	 */
+	  case LOC_OPTIMIZED_OUT:	/* optimized out	 */
+	    print_me = 0;
+	    break;
 
-	    case LOC_ARG:	/* argument              */
-	    case LOC_REF_ARG:	/* reference arg         */
-	    case LOC_REGPARM_ADDR:	/* indirect register arg */
-	    case LOC_LOCAL:	/* stack local           */
-	    case LOC_STATIC:	/* static                */
-	    case LOC_REGISTER:	/* register              */
-	    case LOC_COMPUTED:	/* computed location     */
-	      if (what == all)
-		print_me = 1;
-	      else if (what == locals)
-		print_me = !sym->is_argument ();
-	      else
-		print_me = sym->is_argument ();
-	      break;
-	    }
-	  if (print_me)
-	    {
-	      struct symbol *sym2;
-	      struct frame_arg arg, entryarg;
-
-	      if (sym->is_argument ())
-		sym2 = (lookup_symbol_search_name
-			(sym->search_name (),
-			 block, SEARCH_VAR_DOMAIN).symbol);
-	      else
-		sym2 = sym;
-	      gdb_assert (sym2 != NULL);
-
-	      arg.sym = sym2;
-	      arg.entry_kind = print_entry_values_no;
-	      entryarg.sym = sym2;
-	      entryarg.entry_kind = print_entry_values_no;
-
-	      switch (values)
-		{
-		case PRINT_SIMPLE_VALUES:
-		  if (!mi_simple_type_p (sym2->type ()))
-		    break;
-		  [[fallthrough]];
-
-		case PRINT_ALL_VALUES:
-		  if (sym->is_argument ())
-		    read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
-		  else
-		    read_frame_local (sym2, fi, &arg);
+	  case LOC_ARG:			/* argument		 */
+	  case LOC_REF_ARG:		/* reference arg	 */
+	  case LOC_REGPARM_ADDR:	/* indirect register arg */
+	  case LOC_LOCAL:		/* stack local		 */
+	  case LOC_STATIC:		/* static		 */
+	  case LOC_REGISTER:		/* register		 */
+	  case LOC_COMPUTED:		/* computed location	 */
+	    if (what == all)
+	      print_me = 1;
+	    else if (what == locals)
+	      print_me = !sym->is_argument ();
+	    else
+	      print_me = sym->is_argument ();
+	    break;
+	  }
+	if (print_me)
+	  {
+	    struct symbol *sym2;
+	    struct frame_arg arg, entryarg;
+
+	    if (sym->is_argument ())
+	      sym2 = (lookup_symbol_search_name
+		      (sym->search_name (),
+		       block, SEARCH_VAR_DOMAIN).symbol);
+	    else
+	      sym2 = sym;
+	    gdb_assert (sym2 != nullptr);
+
+	    arg.sym = sym2;
+	    arg.entry_kind = print_entry_values_no;
+	    entryarg.sym = sym2;
+	    entryarg.entry_kind = print_entry_values_no;
+
+	    switch (values)
+	      {
+	      case PRINT_SIMPLE_VALUES:
+		if (!mi_simple_type_p (sym2->type ()))
 		  break;
-		}
-
-	      if (arg.entry_kind != print_entry_values_only)
-		list_arg_or_local (&arg, what, values, skip_unavailable,
-				   fp_opts);
-	      if (entryarg.entry_kind != print_entry_values_no)
-		list_arg_or_local (&entryarg, what, values, skip_unavailable,
-				   fp_opts);
-	    }
-	}
+		[[fallthrough]];
 
-      if (block->function ())
-	break;
-      else
-	block = block->superblock ();
-    }
+	      case PRINT_ALL_VALUES:
+		if (sym->is_argument ())
+		  read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
+		else
+		  read_frame_local (sym2, fi, &arg);
+		break;
+	      }
+
+	    if (arg.entry_kind != print_entry_values_only)
+	      list_arg_or_local (&arg, what, values, skip_unavailable,
+				 fp_opts);
+	    if (entryarg.entry_kind != print_entry_values_no)
+	      list_arg_or_local (&entryarg, what, values, skip_unavailable,
+				 fp_opts);
+	  }
+      }
 }
 
 /* Read a frame specification from FRAME_EXP and return the selected frame.
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 6dc5e11cf87..cb19496d46b 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -635,7 +635,7 @@ pending_framepy_block (PyObject *self, PyObject *args)
   PENDING_FRAMEPY_REQUIRE_VALID (pending_frame);
 
   frame_info_ptr frame = pending_frame->frame_info;
-  const struct block *block = nullptr, *fn_block;
+  const struct block *block = nullptr;
 
   try
     {
diff --git a/gdb/stack.c b/gdb/stack.c
index 6fcc26417e2..e9a01d16a3b 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2232,16 +2232,11 @@ void
 iterate_over_block_local_vars (const struct block *block,
 			       iterate_over_block_arg_local_vars_cb cb)
 {
-  while (block)
-    {
-      iterate_over_block_locals (block, cb);
-      /* After handling the function's top-level block, stop.  Don't
-	 continue to its superblock, the block of per-file
-	 symbols.  */
-      if (block->function ())
-	break;
-      block = block->superblock ();
-    }
+  /* After handling the function's top-level block, stop.  Don't
+     continue to its superblock, the block of per-file
+     symbols.  */
+  for (auto b : block::block_and_superblocks_in_fn (block))
+    iterate_over_block_locals (b, cb);
 }
 
 /* Data to be passed around in the calls to the locals and args
diff --git a/gdb/symtab.c b/gdb/symtab.c
index d8e4e6375d9..9836a7abb38 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2002,22 +2002,19 @@ lookup_language_this (const struct language_defn *lang,
   lookup_name_info this_name (lang->name_of_this (),
 			      symbol_name_match_type::SEARCH_NAME);
 
-  while (block)
+  for (auto b : block::block_and_superblocks_in_fn (block))
     {
       struct symbol *sym;
 
-      sym = block_lookup_symbol (block, this_name, SEARCH_VFT);
+      sym = block_lookup_symbol (b, this_name, SEARCH_VFT);
       if (sym != NULL)
 	{
 	  symbol_lookup_debug_printf_v
 	    ("lookup_language_this (...) = %s (%s, block %s)",
 	     sym->print_name (), host_address_to_string (sym),
-	     host_address_to_string (block));
-	  return (struct block_symbol) {sym, block};
+	     host_address_to_string (b));
+	  return (struct block_symbol) {sym, b};
 	}
-      if (block->function ())
-	break;
-      block = block->superblock ();
     }
 
   symbol_lookup_debug_printf_v ("lookup_language_this (...) = NULL");
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 7f078684b14..5608f81211a 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2456,7 +2456,6 @@ tfind_outside_command (const char *args, int from_tty)
 static void
 info_scope_command (const char *args_in, int from_tty)
 {
-  const struct block *block;
   const char *symname;
   const char *save_args = args_in;
   int j, count = 0;
@@ -2481,9 +2480,9 @@ info_scope_command (const char *args_in, int from_tty)
 
   /* Resolve line numbers to PC.  */
   resolve_sal_pc (&sals[0]);
-  block = block_for_pc (sals[0].pc);
+  const struct block *pc_block = block_for_pc (sals[0].pc);
 
-  while (block != 0)
+  for (auto block : block::block_and_superblocks_in_fn (pc_block))
     {
       QUIT;			/* Allow user to bail out with ^C.  */
       for (struct symbol *sym : block_iterator_range (block))
@@ -2607,10 +2606,6 @@ info_scope_command (const char *args_in, int from_tty)
 	      gdb_printf (", length %s.\n", pulongest (t->length ()));
 	    }
 	}
-      if (block->function ())
-	break;
-      else
-	block = block->superblock ();
     }
   if (count <= 0)
     gdb_printf ("Scope for %s contains no locals or arguments.\n",
-- 
2.51.0


  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 ` [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
2026-05-01 12:45 ` [PATCH 09/10] [gdb] Add block::block_and_superblocks_in_fn Tom de Vries
2026-05-01 12:45 ` Tom de Vries [this message]
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-11-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