Simplify block_find_symbol

block_find_symbol takes a callback function, but only two callbacks
are ever passed to it -- and they are similar enough that it seems
cleaner to just have block_find_symbol do the work itself.  Also,
block_find_symbol can take a lookup_name_info as an argument,
following the general idea of pushing the construction of these
objects as high in the call chain as feasible.

Regression tested on x86-64 Fedora 38.

Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
This commit is contained in:
Tom Tromey
2023-03-30 08:41:17 -06:00
parent def2803789
commit b7a92724c5
4 changed files with 27 additions and 75 deletions

View File

@@ -778,46 +778,25 @@ block_lookup_symbol_primary (const struct block *block, const char *name,
/* See block.h. */
struct symbol *
block_find_symbol (const struct block *block, const char *name,
const domain_enum domain,
block_symbol_matcher_ftype *matcher, void *data)
block_find_symbol (const struct block *block, const lookup_name_info &name,
const domain_enum domain, struct symbol **stub)
{
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);
for (struct symbol *sym : block_iterator_range (block, &lookup_name))
for (struct symbol *sym : block_iterator_range (block, &name))
{
/* MATCHER is deliberately called second here so that it never sees
a non-domain-matching symbol. */
if (sym->matches (domain)
&& matcher (sym, data))
if (!sym->matches (domain))
continue;
if (!TYPE_IS_OPAQUE (sym->type ()))
return sym;
if (stub != nullptr)
*stub = sym;
}
return NULL;
}
/* See block.h. */
int
block_find_non_opaque_type (struct symbol *sym, void *data)
{
return !TYPE_IS_OPAQUE (sym->type ());
}
/* See block.h. */
int
block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
{
struct symbol **best = (struct symbol **) data;
if (!TYPE_IS_OPAQUE (sym->type ()))
return 1;
*best = sym;
return 0;
return nullptr;
}
/* See block.h. */