[PATCH v2 22/28] Pass lookup_name_info to block_lookup_symbol_primary

Tom Tromey
2025-04-03T00:04:46Z

This changes block_lookup_symbol_primary to accept a lookup_name_info.
This follows the general trend of hoisting these objects to the
outermost layer where they make sense -- somewhat reducing the cost of
using them.
---
gdb/block.c | 7 +++----
gdb/block.h | 2 +-
gdb/symtab.c | 3 ++-
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 2c07b38f8f806b8a154eb42adbd3f53a3535c57f..583c4ef1bf07ab942af71d0f1d1b38799849451d 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -718,17 +718,16 @@ block_lookup_symbol (const struct block *block, const lookup_name_info &name,
/* See block.h. */

struct symbol *
-block_lookup_symbol_primary (const struct block *block, const char *name,
+block_lookup_symbol_primary (const struct block *block,
+ const lookup_name_info &name,
const domain_search_flags domain)
{
- lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
/* 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, &lookup_name))
+ for (symbol *sym : block_iterator_range (block, &name))
{
/* With the fix for PR gcc/debug/91507, we get for:
...
diff --git a/gdb/block.h b/gdb/block.h
index 75f5c8e93944342782343ebfb9b5b99afce1d4ff..c348c7fdcc4088e7f5c912e49c387e2c650eda45 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -636,7 +636,7 @@ extern struct symbol *block_lookup_symbol (const struct block *block,

extern struct symbol *block_lookup_symbol_primary
(const struct block *block,
- const char *name,
+ const lookup_name_info &name,
const domain_search_flags domain);

/* Find symbol NAME in BLOCK and in DOMAIN. This will return a
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 508374f1358e92108db7546246e2323c5d7b5905..4822b5681f8370394c9cb6ca6c38ac2214191a39 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2365,6 +2365,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
name, domain_name (domain).c_str ());

+ lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
struct block_symbol other;
other.symbol = NULL;
for (compunit_symtab *cust : objfile->compunits ())
@@ -2375,7 +2376,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile,

bv = cust->blockvector ();
block = bv->block (block_index);
- result.symbol = block_lookup_symbol_primary (block, name, domain);
+ result.symbol = block_lookup_symbol_primary (block, lookup_name, domain);
result.block = block;
if (result.symbol == NULL)
continue;

--
2.46.1