From 0b7b2c2adff43d39ee3bd39ebd91a6710d9175e4 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 17 Apr 2021 09:35:04 -0600 Subject: Simplify quick_symbol_functions::map_matching_symbols quick_symbol_functions::map_matching_symbols is only used by the Ada code. Currently, it both expands certain psymtabs and then walks over the full symtabs -- including any already-expanded ones -- calling a callback. It appears to work lazily as well, in that if the callback returns false, iteration stops. However, only the psymtab implementation does this; the DWARF index implementations are not lazy. It turns out, though, that the only callback that is ever passed here never returns false. This patch simplifies this method by removing the callback. The method is also renamed. In the new scheme, the caller is responsible for walking the full symtabs, which removes some redundancy as well. gdb/ChangeLog 2021-04-17 Tom Tromey * psymtab.c (psymbol_functions::expand_matching_symbols): Rename from map_matching_symbols. Change parameters. * psympriv.h (struct psymbol_functions) : Rename from map_matching_symbols. Change parameters. * dwarf2/read.c (struct dwarf2_gdb_index) : Rename from map_matching_symbols. Change parameters. (struct dwarf2_debug_names_index) : Rename from map_matching_symbols. Change parameters. (dwarf2_gdb_index::expand_matching_symbols): Rename from dw2_map_matching_symbols. Change parameters. (dwarf2_gdb_index::expand_matching_symbols): Remove old implementation. (dwarf2_debug_names_index::expand_matching_symbols): Rename from map_matching_symbols. Change parameters. * objfiles.h (struct objfile) : Rename from map_matching_symbols. Change parameters. * symfile-debug.c (objfile::expand_matching_symbols): Rename from map_matching_symbols. Change parameters. * ada-lang.c (map_matching_symbols): New function. (add_nonlocal_symbols): Update. --- gdb/ada-lang.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'gdb/ada-lang.c') diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 589fbf1..d170a1e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5175,6 +5175,33 @@ ada_lookup_name (const lookup_name_info &lookup_name) return lookup_name.ada ().lookup_name ().c_str (); } +/* A helper for add_nonlocal_symbols. Call expand_matching_symbols + for OBJFILE, then walk the objfile's symtabs and update the + results. */ + +static void +map_matching_symbols (struct objfile *objfile, + const lookup_name_info &lookup_name, + bool is_wild_match, + domain_enum domain, + int global, + match_data &data) +{ + data.objfile = objfile; + objfile->expand_matching_symbols (lookup_name, domain, global, + is_wild_match ? nullptr : compare_names); + + const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; + for (compunit_symtab *symtab : objfile->compunits ()) + { + const struct block *block + = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind); + if (!iterate_over_symbols_terminated (block, lookup_name, + domain, data)) + break; + } +} + /* Add to RESULT all non-local symbols whose name and domain match LOOKUP_NAME and DOMAIN respectively. The search is performed on GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK @@ -5191,10 +5218,8 @@ add_nonlocal_symbols (std::vector &result, for (objfile *objfile : current_program_space->objfiles ()) { - data.objfile = objfile; - - objfile->map_matching_symbols (lookup_name, domain, global, data, - is_wild_match ? NULL : compare_names); + map_matching_symbols (objfile, lookup_name, is_wild_match, domain, + global, data); for (compunit_symtab *cu : objfile->compunits ()) { @@ -5214,12 +5239,8 @@ add_nonlocal_symbols (std::vector &result, lookup_name_info name1 (bracket_name, symbol_name_match_type::FULL); for (objfile *objfile : current_program_space->objfiles ()) - { - data.objfile = objfile; - objfile->map_matching_symbols (name1, domain, global, data, - compare_names); - } - } + map_matching_symbols (objfile, name1, false, domain, global, data); + } } /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if -- cgit v1.1