+2021-04-17 Tom Tromey <tom@tromey.com>
+
+ * symfile-debug.c (objfile::lookup_symbol): Rewrite.
+ * quick-symbol.h (struct quick_symbol_functions) <lookup_symbol>:
+ Remove.
+ * psymtab.c (psymbol_functions::lookup_symbol): Remove.
+ * psympriv.h (struct psymbol_functions) <lookup_symbol>: Remove.
+ * objfiles.h (struct objfile) <lookup_symbol>: Add comment.
+ * dwarf2/read.c (struct dwarf2_gdb_index) <lookup_symbol>:
+ Remove.
+ (struct dwarf2_debug_names_index) <lookup_symbol>: Remove.
+ (dwarf2_gdb_index::lookup_symbol)
+ (dwarf2_debug_names_index::lookup_symbol): Remove.
+
2021-04-17 Tom Tromey <tom@tromey.com>
* symtab.c (global_symbol_searcher::expand_symtabs): Update.
struct dwarf2_gdb_index : public dwarf2_base_index_functions
{
- struct compunit_symtab *lookup_symbol (struct objfile *objfile,
- block_enum block_index,
- const char *name,
- domain_enum domain) override;
-
void dump (struct objfile *objfile) override;
void expand_symtabs_for_function (struct objfile *objfile,
struct dwarf2_debug_names_index : public dwarf2_base_index_functions
{
- struct compunit_symtab *lookup_symbol (struct objfile *objfile,
- block_enum block_index,
- const char *name,
- domain_enum domain) override;
-
void dump (struct objfile *objfile) override;
void expand_symtabs_for_function (struct objfile *objfile,
return NULL;
}
-struct compunit_symtab *
-dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
- block_enum block_index,
- const char *name, domain_enum domain)
-{
- struct compunit_symtab *stab_best = NULL;
- dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
- lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
- struct dw2_symtab_iterator iter;
- struct dwarf2_per_cu_data *per_cu;
-
- dw2_symtab_iter_init (&iter, per_objfile, block_index, domain, name);
-
- while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
- {
- struct symbol *sym, *with_opaque = NULL;
- struct compunit_symtab *stab
- = dw2_instantiate_symtab (per_cu, per_objfile, false);
- const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
- const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
- sym = block_find_symbol (block, name, domain,
- block_find_non_opaque_type_preferred,
- &with_opaque);
-
- /* Some caution must be observed with overloaded functions
- and methods, since the index will not contain any overload
- information (but NAME might contain it). */
-
- if (sym != NULL
- && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
- return stab;
- if (with_opaque != NULL
- && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
- stab_best = stab;
-
- /* Keep looking through other CUs. */
- }
-
- return stab_best;
-}
-
void
dwarf2_base_index_functions::print_stats (struct objfile *objfile,
bool print_bcache)
return per_cu;
}
-struct compunit_symtab *
-dwarf2_debug_names_index::lookup_symbol
- (struct objfile *objfile, block_enum block_index,
- const char *name, domain_enum domain)
-{
- dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
- const auto &mapp = per_objfile->per_bfd->debug_names_table;
- if (!mapp)
- {
- /* index is NULL if OBJF_READNOW. */
- return NULL;
- }
- const auto &map = *mapp;
-
- dw2_debug_names_iterator iter (map,
- block_index == GLOBAL_BLOCK
- ? SEARCH_GLOBAL_BLOCK
- : SEARCH_STATIC_BLOCK,
- domain, name, per_objfile);
-
- struct compunit_symtab *stab_best = NULL;
- struct dwarf2_per_cu_data *per_cu;
- while ((per_cu = iter.next ()) != NULL)
- {
- struct symbol *sym, *with_opaque = NULL;
- compunit_symtab *stab
- = dw2_instantiate_symtab (per_cu, per_objfile, false);
- const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
- const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
- sym = block_find_symbol (block, name, domain,
- block_find_non_opaque_type_preferred,
- &with_opaque);
-
- /* Some caution must be observed with overloaded functions and
- methods, since the index will not contain any overload
- information (but NAME might contain it). */
-
- if (sym != NULL
- && strcmp_iw (sym->search_name (), name) == 0)
- return stab;
- if (with_opaque != NULL
- && strcmp_iw (with_opaque->search_name (), name) == 0)
- stab_best = stab;
-
- /* Keep looking through other CUs. */
- }
-
- return stab_best;
-}
-
/* This dumps minimal information about .debug_names. It is called
via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
uses this to verify that .debug_names has been loaded. */
(const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback);
- /* See quick_symbol_functions. */
+ /* Check to see if the symbol is defined in a "partial" symbol table
+ of this objfile. BLOCK_INDEX should be either GLOBAL_BLOCK or
+ STATIC_BLOCK, depending on whether we want to search global
+ symbols or static symbols. NAME is the name of the symbol to
+ look for. DOMAIN indicates what sort of symbol to search for.
+
+ Returns the newly-expanded compunit in which the symbol is
+ defined, or NULL if no such symbol table exists. If OBJFILE
+ contains !TYPE_OPAQUE symbol prefer its compunit. If it contains
+ only TYPE_OPAQUE symbol(s), return at least that compunit. */
struct compunit_symtab *lookup_symbol (block_enum kind, const char *name,
domain_enum domain);
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback) override;
- struct compunit_symtab *lookup_symbol (struct objfile *objfile,
- block_enum block_index,
- const char *name,
- domain_enum domain) override;
-
enum language lookup_global_symbol_language (struct objfile *objfile,
const char *name,
domain_enum domain,
return best;
}
-/* Psymtab version of lookup_symbol. See its definition in
- the definition of quick_symbol_functions in symfile.h. */
-
-struct compunit_symtab *
-psymbol_functions::lookup_symbol (struct objfile *objfile,
- block_enum block_index, const char *name,
- const domain_enum domain)
-{
- const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
- struct compunit_symtab *stab_best = NULL;
-
- lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
- lookup_name_info psym_lookup_name = lookup_name.make_ignore_params ();
-
- for (partial_symtab *ps : require_partial_symbols (objfile))
- {
- if (!ps->readin_p (objfile)
- && lookup_partial_symbol (objfile, ps, psym_lookup_name,
- psymtab_index, domain))
- {
- struct symbol *sym, *with_opaque = NULL;
- struct compunit_symtab *stab = psymtab_to_symtab (objfile, ps);
- /* Note: While psymtab_to_symtab can return NULL if the
- partial symtab is empty, we can assume it won't here
- because lookup_partial_symbol succeeded. */
- const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
- const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
- sym = block_find_symbol (block, name, domain,
- block_find_non_opaque_type_preferred,
- &with_opaque);
-
- /* Some caution must be observed with overloaded functions
- and methods, since the index will not contain any overload
- information (but NAME might contain it). */
-
- if (sym != NULL
- && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
- return stab;
- if (with_opaque != NULL
- && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
- stab_best = stab;
-
- /* Keep looking through other psymtabs. */
- }
- }
-
- return stab_best;
-}
-
/* Psymtab version of lookup_global_symbol_language. See its definition in
the definition of quick_symbol_functions in symfile.h. */
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback) = 0;
- /* Check to see if the symbol is defined in a "partial" symbol table
- of OBJFILE. BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
- depending on whether we want to search global symbols or static
- symbols. NAME is the name of the symbol to look for. DOMAIN
- indicates what sort of symbol to search for.
-
- Returns the newly-expanded compunit in which the symbol is
- defined, or NULL if no such symbol table exists. If OBJFILE
- contains !TYPE_OPAQUE symbol prefer its compunit. If it contains
- only TYPE_OPAQUE symbol(s), return at least that compunit. */
- virtual struct compunit_symtab *lookup_symbol (struct objfile *objfile,
- block_enum block_index,
- const char *name,
- domain_enum domain) = 0;
-
/* Check to see if the global symbol is defined in a "partial" symbol table
of OBJFILE. NAME is the name of the symbol to look for. DOMAIN
indicates what sort of symbol to search for.
#include "source.h"
#include "symtab.h"
#include "symfile.h"
+#include "block.h"
/* We need to save a pointer to the real symbol functions.
Plus, the debug versions are malloc'd because we have to NULL out the
objfile_debug_name (this), kind, name,
domain_name (domain));
+ lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+
+ auto search_one_symtab = [&] (compunit_symtab *stab)
+ {
+ struct symbol *sym, *with_opaque = NULL;
+ const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
+ const struct block *block = BLOCKVECTOR_BLOCK (bv, kind);
+
+ sym = block_find_symbol (block, name, domain,
+ block_find_non_opaque_type_preferred,
+ &with_opaque);
+
+ /* Some caution must be observed with overloaded functions
+ and methods, since the index will not contain any overload
+ information (but NAME might contain it). */
+
+ if (sym != NULL
+ && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
+ {
+ retval = stab;
+ /* Found it. */
+ return false;
+ }
+ if (with_opaque != NULL
+ && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
+ retval = stab;
+
+ /* Keep looking through other psymtabs. */
+ return true;
+ };
+
for (const auto &iter : qf)
{
- retval = iter->lookup_symbol (this, kind, name, domain);
- if (retval != nullptr)
+ if (!iter->expand_symtabs_matching (this,
+ nullptr,
+ &lookup_name,
+ nullptr,
+ search_one_symtab,
+ kind == GLOBAL_BLOCK
+ ? SEARCH_GLOBAL_BLOCK
+ : SEARCH_STATIC_BLOCK,
+ domain,
+ ALL_DOMAIN))
break;
}