@@ -5402,17 +5402,15 @@ ada_add_local_symbols (std::vector<struct block_symbol> &result,
const lookup_name_info &lookup_name,
const struct block *block, domain_search_flags domain)
{
- while (block != NULL)
+ for (auto b : block::block_and_superblocks (block))
{
- ada_add_block_symbols (result, block, lookup_name, domain, NULL);
+ ada_add_block_symbols (result, b, lookup_name, domain, nullptr);
/* If we found a non-function match, assume that's the one. We
only check this when finding a function boundary, so that we
can accumulate all results from intervening blocks first. */
- if (block->function () != nullptr && is_nonfunction (result))
+ if (b->function () != nullptr && is_nonfunction (result))
return;
-
- block = block->superblock ();
}
}
@@ -13825,9 +13823,7 @@ class ada_language : public language_defn
/* Search upwards from currently selected frame (so that we can
complete on local vars. */
- for (const block *b = get_selected_block (0);
- b != nullptr;
- b = b->superblock ())
+ for (auto b : block::block_and_superblocks (get_selected_block (0)))
{
if (b->is_static_block ())
surrounding_static_block = b; /* For elmin of dups */
@@ -13852,9 +13848,9 @@ class ada_language : public language_defn
auto callback = [&] (compunit_symtab *s)
{
QUIT;
- for (const block *b = s->blockvector ()->static_block ();
- b != nullptr;
- b = b->superblock ())
+ const struct block *static_block
+ = s->blockvector ()->static_block ();
+ for (auto b : block::block_and_superblocks (static_block))
{
/* Don't do this block twice. */
if (b == surrounding_static_block)
@@ -69,13 +69,14 @@ get_frame_block (const frame_info_ptr &frame, CORE_ADDR *addr_in_block)
inline_count = frame_inlined_callees (frame);
- while (inline_count > 0)
+ auto range = bl->block_and_superblocks ();
+ for (auto b = range.begin (); b != range.end (); ++b, bl = *b)
{
- if (bl->inlined_p ())
- inline_count--;
+ if (inline_count <= 0)
+ break;
- bl = bl->superblock ();
- gdb_assert (bl != NULL);
+ if ((*b)->inlined_p ())
+ inline_count--;
}
return bl;
@@ -443,10 +443,12 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
continue;
function_block = block;
- while (function_block != bv->static_block ()
- && function_block != bv->global_block ())
+ for (auto b : block::block_and_superblocks (block))
{
- function_block = function_block->superblock ();
+ if (b == bv->static_block () || b == bv->global_block ())
+ break;
+
+ function_block = b->superblock ();
function = function_block->function ();
if (function != NULL)
break;
@@ -613,13 +613,11 @@ cp_lookup_symbol_via_all_imports (const char *scope, const char *name,
{
struct block_symbol sym;
- while (block != NULL)
+ for (auto b : block::block_and_superblocks (block))
{
- sym = cp_lookup_symbol_via_imports (scope, name, block, domain, 0, 1);
+ sym = cp_lookup_symbol_via_imports (scope, name, b, domain, 0, 1);
if (sym.symbol != nullptr)
return sym;
-
- block = block->superblock ();
}
return {};
@@ -1408,15 +1408,11 @@ add_symbol_overload_list_using (const char *func_name,
const char *the_namespace,
std::vector<symbol *> *overload_list)
{
- const struct block *block;
-
/* First, go through the using directives. If any of them apply,
look in the appropriate namespaces for new functions to match
on. */
- for (block = get_selected_block (0);
- block != NULL;
- block = block->superblock ())
+ for (auto block : block::block_and_superblocks (get_selected_block (0)))
for (using_direct *current : block->get_using ())
{
/* Prevent recursive calls. */
@@ -1459,7 +1455,7 @@ add_symbol_overload_list_qualified (const char *func_name,
/* Search upwards from currently selected frame (so that we can
complete on local vars. */
- for (const block *b = selected_block; b != nullptr; b = b->superblock ())
+ for (auto b : block::block_and_superblocks (selected_block))
add_symbol_overload_list_block (func_name, b, overload_list);
const block *surrounding_static_block = (selected_block == nullptr
@@ -481,14 +481,12 @@ d_lookup_symbol_module (const char *scope, const char *name,
/* Search for name in modules imported to this and parent
blocks. */
- while (block != NULL)
+ for (auto b : block::block_and_superblocks (block))
{
- sym = d_lookup_symbol_imports (scope, name, block, domain);
+ sym = d_lookup_symbol_imports (scope, name, b, domain);
if (sym.symbol != NULL)
return sym;
-
- block = block->superblock ();
}
return {};
@@ -373,21 +373,15 @@ dwarf_find_and_extend_inline_block_range (dwarf2_cu *cu,
the child of a non-inline block. This is new inline block is our
candidate for extending. */
struct block *block = nullptr;
- for (const struct block *b = it->second;
- b != nullptr;
- b = b->superblock ())
- {
- if (b->function () != nullptr && b->inlined_p ())
- {
- if (b->superblock () != nullptr
- && b->superblock ()->function () != nullptr
- && !b->superblock ()->inlined_p ())
- {
- block = const_cast<struct block *> (b);
- break;
- }
- }
- }
+ for (auto b : block::block_and_superblocks (it->second))
+ if (b->inlined_p ()
+ && b->superblock () != nullptr
+ && b->superblock ()->function () != nullptr
+ && !b->superblock ()->inlined_p ())
+ {
+ block = const_cast<struct block *> (b);
+ break;
+ }
/* If we didn't find a block, or the block we found wasn't called from
the expected LINE, then we're done. Maybe we should try harder to
@@ -8261,13 +8261,15 @@ process_event_stop_test (struct execution_control_state *ecs)
const struct block *prev
= block_for_pc (ecs->event_thread->control.step_frame_id.code_addr);
const struct block *curr = block_for_pc (ecs->event_thread->stop_pc ());
- while (curr != nullptr && !curr->contains (prev))
+ for (auto b : block::block_and_superblocks (curr))
{
- if (curr->inlined_p ())
+ if (b->contains (prev))
+ break;
+
+ if (b->inlined_p ())
depth++;
- else if (curr->function () != nullptr)
+ else if (b->function () != nullptr)
break;
- curr = curr->superblock ();
}
while (inline_skipped_frames (ecs->event_thread) > depth)
step_into_inline_frame (ecs->event_thread);
@@ -217,7 +217,7 @@ inline_frame_sniffer (const struct frame_unwind *self,
void **this_cache)
{
CORE_ADDR this_pc;
- const struct block *frame_block, *cur_block;
+ const struct block *frame_block;
int depth;
frame_info_ptr next_frame;
struct inline_state *state = find_inline_frame_state (inferior_thread ());
@@ -230,15 +230,15 @@ inline_frame_sniffer (const struct frame_unwind *self,
/* Calculate DEPTH, the number of inlined functions at this
location. */
depth = 0;
- cur_block = frame_block;
- while (cur_block->superblock ())
+ for (auto cur_block : frame_block->block_and_superblocks ())
{
+ if (cur_block->superblock () == nullptr)
+ break;
+
if (cur_block->inlined_p ())
depth++;
else if (cur_block->function () != NULL)
break;
-
- cur_block = cur_block->superblock ();
}
/* Check how many inlined functions already have frames. */
@@ -361,25 +361,22 @@ gather_inline_frames (CORE_ADDR this_pc)
return {};
std::vector<const symbol *> function_symbols;
- while (cur_block != nullptr)
- {
- if (cur_block->inlined_p ())
- {
- gdb_assert (cur_block->function () != nullptr);
-
- /* See comments in inline_frame_this_id about this use
- of BLOCK_ENTRY_PC. */
- if (cur_block->entry_pc () == this_pc
- || block_starting_point_at (bv, this_pc, cur_block))
- function_symbols.push_back (cur_block->function ());
- else
- break;
- }
- else if (cur_block->function () != nullptr)
- break;
-
- cur_block = cur_block->superblock ();
- }
+ auto range = block::block_and_superblocks (cur_block);
+ for (auto b = range.begin (); b != range.end (); ++b, cur_block = *b)
+ if (cur_block->inlined_p ())
+ {
+ gdb_assert (cur_block->function () != nullptr);
+
+ /* See comments in inline_frame_this_id about this use
+ of BLOCK_ENTRY_PC. */
+ if (cur_block->entry_pc () == this_pc
+ || block_starting_point_at (bv, this_pc, cur_block))
+ function_symbols.push_back (cur_block->function ());
+ else
+ break;
+ }
+ else if (cur_block->function () != nullptr)
+ break;
/* If we have a code region for which we have no function blocks,
possibly due to bad debug, or possibly just when some debug
@@ -1194,11 +1194,10 @@ iterate_over_file_blocks
domain_search_flags domain,
for_each_symbol_callback_ftype callback)
{
- const struct block *block;
+ const struct block *static_block
+ = symtab->compunit ()->blockvector ()->static_block ();
- for (block = symtab->compunit ()->blockvector ()->static_block ();
- block != NULL;
- block = block->superblock ())
+ for (auto block : block::block_and_superblocks (static_block))
current_language->for_each_symbol (block, name, domain, callback);
}
@@ -961,11 +961,10 @@ block_depth (const struct block *block)
{
int i = 0;
- while ((block = block->superblock ()) != NULL)
- {
- i++;
- }
- return i;
+ for (auto b [[maybe_unused]]: block::block_and_superblocks (block))
+ i++;
+
+ return i - 1;
}
@@ -2181,14 +2181,17 @@ lookup_local_symbol (const char *name,
const char *scope = block->scope ();
- while (!block->is_global_block () && !block->is_static_block ())
+ for (auto b : block->block_and_superblocks ())
{
+ if (b->is_global_block () || b->is_static_block ())
+ break;
+
struct symbol *sym = lookup_symbol_in_block (name, match_type,
- block, domain);
+ b, domain);
if (sym != NULL)
- return (struct block_symbol) {sym, block};
+ return (struct block_symbol) {sym, b};
- struct symbol *function = block->function ();
+ struct symbol *function = b->function ();
if (function != nullptr && function->is_template_function ())
{
struct template_symbol *templ = (struct template_symbol *) function;
@@ -2196,17 +2199,16 @@ lookup_local_symbol (const char *name,
templ->n_template_arguments,
templ->template_arguments);
if (sym != nullptr)
- return (struct block_symbol) {sym, block};
+ return (struct block_symbol) {sym, b};
}
struct block_symbol blocksym
- = langdef->lookup_symbol_local (scope, name, block, domain);
+ = langdef->lookup_symbol_local (scope, name, b, domain);
if (blocksym.symbol != nullptr)
return blocksym;
- if (block->inlined_p ())
+ if (b->inlined_p ())
break;
- block = block->superblock ();
}
/* We've reached the end of the function without finding a result. */
@@ -3829,13 +3831,17 @@ skip_prologue_sal (struct symtab_and_line *sal)
use the call site of the function instead. */
const block *function_block = nullptr;
- for (const block *b = block_for_pc_sect (sal->pc, sal->section);
- b != nullptr;
- b = b->superblock ())
- if (b->function () != NULL && b->inlined_p ())
- function_block = b;
- else if (b->function () != NULL)
- break;
+ const block *pc_block = block_for_pc_sect (sal->pc, sal->section);
+ for (auto b: block::block_and_superblocks (pc_block))
+ {
+ if (b->function () == nullptr)
+ continue;
+
+ if (b->inlined_p ())
+ function_block = b;
+ else
+ break;
+ }
if (function_block != NULL
&& function_block->function ()->line () != 0)
@@ -3929,7 +3935,8 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
same function, not something inlined. If it's inlined,
then there is no point comparing the line numbers. */
bl = block_for_pc (prologue_sal.end);
- while (bl)
+ auto range = block::block_and_superblocks (bl);
+ for (auto b = range.begin (); b != range.end (); ++b, bl = *b)
{
if (bl->inlined_p ())
break;
@@ -3938,7 +3945,6 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
bl = NULL;
break;
}
- bl = bl->superblock ();
}
if (bl != NULL)
break;
@@ -5868,7 +5874,7 @@ default_collect_symbol_completion_matches_break_on
frees them. I'm not going to worry about this; hopefully there
won't be that many. */
- const struct block *b;
+ const struct block *selected_block;
const struct block *surrounding_static_block, *surrounding_global_block;
/* The symbol we are completing on. Points in same buffer as text. */
const char *sym_text;
@@ -5977,12 +5983,17 @@ default_collect_symbol_completion_matches_break_on
this places which match our text string. Only complete on types
visible from current context. */
- b = get_selected_block (0);
- surrounding_static_block = b == nullptr ? nullptr : b->static_block ();
- surrounding_global_block = b == nullptr ? nullptr : b->global_block ();
+ selected_block = get_selected_block (0);
+ surrounding_static_block
+ = selected_block == nullptr ? nullptr : selected_block->static_block ();
+ surrounding_global_block
+ = selected_block == nullptr ? nullptr : selected_block->global_block ();
if (surrounding_static_block != NULL)
- while (b != surrounding_static_block)
+ for (auto b : block::block_and_superblocks (selected_block))
{
+ if (b == surrounding_static_block)
+ break;
+
QUIT;
for (struct symbol *sym : block_iterator_range (b))
@@ -6003,9 +6014,8 @@ default_collect_symbol_completion_matches_break_on
/* Stop when we encounter an enclosing function. Do not stop for
non-inlined functions - the locals of the enclosing function
are in scope for a nested function. */
- if (b->function () != NULL && b->inlined_p ())
+ if (b->inlined_p ())
break;
- b = b->superblock ();
}
/* Add fields from the file's types; symbols will be added below. */