@@ -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
@@ -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;
@@ -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)
{
@@ -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.
@@ -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
{
@@ -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
@@ -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");
@@ -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",