[PATCH v2 23/28] Simplify block_lookup_symbol

Tom Tromey
2025-04-02T23:54:43Z

One loop in block_lookup_symbol is identical to the code in
block_lookup_symbol_primary. This patch simplifies the former by
having it call the latter.

This removes an assert. However, note that the assert is not needed
-- it does not check any invariant that must be maintained.
---
gdb/block.c | 23 +----------------------
1 file changed, 1 insertion(+), 22 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 583c4ef1bf07ab942af71d0f1d1b38799849451d..d8f8bf56de7b1498ae3f89650a3c86c4eafe3bfe 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -669,24 +669,7 @@ block_lookup_symbol (const struct block *block, const lookup_name_info &name,
const domain_search_flags domain)
{
if (!block->function ())
- {
- struct symbol *other = NULL;
-
- for (struct symbol *sym : block_iterator_range (block, &name))
- {
- /* See comment related to PR gcc/debug/91507 in
- block_lookup_symbol_primary. */
- if (best_symbol (sym, domain))
- return sym;
- /* This is a bit of a hack, but symbol_matches_domain might ignore
- STRUCT vs VAR domain symbols. So if a matching symbol is found,
- make sure there is no "better" matching symbol, i.e., one with
- exactly the same domain. PR 16253. */
- if (sym->matches (domain))
- other = better_symbol (other, sym, domain);
- }
- return other;
- }
+ return block_lookup_symbol_primary (block, name, domain);
else
{
/* Note that parameter symbols do not always show up last in the
@@ -722,10 +705,6 @@ block_lookup_symbol_primary (const struct block *block,
const lookup_name_info &name,
const domain_search_flags domain)
{
- /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
- gdb_assert (block->superblock () == NULL
- || block->superblock ()->superblock () == NULL);
-
symbol *other = nullptr;
for (symbol *sym : block_iterator_range (block, &name))
{

--
2.46.1