From: Tom Tromey Date: Sat, 17 Apr 2021 15:35:04 +0000 (-0600) Subject: Add search_flags to expand_symtabs_matching X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=03a8ea51c31d8f27ec717ddb1ff68f5f5d0732ab;p=binutils-gdb.git Add search_flags to expand_symtabs_matching This adds a block search flags parameter to expand_symtabs_matching. All callers are updated to search both the static and global blocks, as that was the implied behavior before this patch. This is a step toward replacing lookup_symbol with expand_symtabs_matching. gdb/ChangeLog 2021-04-17 Tom Tromey * symtab.c (global_symbol_searcher::expand_symtabs) (default_collect_symbol_completion_matches_break_on): Update. * symmisc.c (maintenance_expand_symtabs): Update. * symfile.h (expand_symtabs_matching): Add search_flags parameter. * symfile.c (expand_symtabs_matching): Add search_flags parameter. * symfile-debug.c (objfile::expand_symtabs_matching): Add search_flags parameter. * quick-symbol.h (struct quick_symbol_functions) : Add search_flags parameter. * python/py-symbol.c (gdbpy_lookup_static_symbols): Update. * psymtab.c (recursively_search_psymtabs) (psymbol_functions::expand_symtabs_matching): Add search_flags parameter. * psympriv.h (struct psymbol_functions) : Add search_flags parameter. * objfiles.h (struct objfile) : Add search_flags parameter. * linespec.c (iterate_over_all_matching_symtabs): Update. * dwarf2/read.c (struct dwarf2_gdb_index) : Add search_flags parameter. (struct dwarf2_debug_names_index) : Add search_flags parameter. (dw2_map_matching_symbols): Update. (dw2_expand_marked_cus, dw2_expand_symtabs_matching) (dwarf2_gdb_index::expand_symtabs_matching): Add search_flags parameter. (dw2_debug_names_iterator): Change block_index to search flags. : Likewise. (dw2_debug_names_iterator::next) (dwarf2_debug_names_index::lookup_symbol) (dwarf2_debug_names_index::expand_symtabs_for_function) (dwarf2_debug_names_index::map_matching_symbols) (dwarf2_debug_names_index::map_matching_symbols): Update. (dwarf2_debug_names_index::expand_symtabs_matching): Add search_flags parameter. * ada-lang.c (ada_add_global_exceptions) (collect_symbol_completion_matches): Update. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f1d21931751..3d27f68b93c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,45 @@ +2021-04-17 Tom Tromey + + * symtab.c (global_symbol_searcher::expand_symtabs) + (default_collect_symbol_completion_matches_break_on): Update. + * symmisc.c (maintenance_expand_symtabs): Update. + * symfile.h (expand_symtabs_matching): Add search_flags + parameter. + * symfile.c (expand_symtabs_matching): Add search_flags + parameter. + * symfile-debug.c (objfile::expand_symtabs_matching): Add + search_flags parameter. + * quick-symbol.h (struct quick_symbol_functions) + : Add search_flags parameter. + * python/py-symbol.c (gdbpy_lookup_static_symbols): Update. + * psymtab.c (recursively_search_psymtabs) + (psymbol_functions::expand_symtabs_matching): Add search_flags + parameter. + * psympriv.h (struct psymbol_functions) : + Add search_flags parameter. + * objfiles.h (struct objfile) : Add + search_flags parameter. + * linespec.c (iterate_over_all_matching_symtabs): Update. + * dwarf2/read.c (struct dwarf2_gdb_index) + : Add search_flags parameter. + (struct dwarf2_debug_names_index) : Add + search_flags parameter. + (dw2_map_matching_symbols): Update. + (dw2_expand_marked_cus, dw2_expand_symtabs_matching) + (dwarf2_gdb_index::expand_symtabs_matching): Add search_flags + parameter. + (dw2_debug_names_iterator): Change block_index to search flags. + : Likewise. + (dw2_debug_names_iterator::next) + (dwarf2_debug_names_index::lookup_symbol) + (dwarf2_debug_names_index::expand_symtabs_for_function) + (dwarf2_debug_names_index::map_matching_symbols) + (dwarf2_debug_names_index::map_matching_symbols): Update. + (dwarf2_debug_names_index::expand_symtabs_matching): Add + search_flags parameter. + * ada-lang.c (ada_add_global_exceptions) + (collect_symbol_completion_matches): Update. + 2021-04-17 Tom Tromey * symtab.c (default_collect_symbol_completion_matches_break_on): diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f7860f27bfc..589fbf1a0c4 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12516,6 +12516,7 @@ ada_add_global_exceptions (compiled_regex *preg, return name_matches_regex (decoded.c_str (), preg); }, NULL, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, VARIABLES_DOMAIN); for (objfile *objfile : current_program_space->objfiles ()) @@ -13032,6 +13033,7 @@ public: lookup_name, NULL, NULL, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, ALL_DOMAIN); /* At this point scan through the misc symbol vectors and add each diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index b1604a13fc2..824945a95bc 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2289,6 +2289,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) override; }; @@ -2318,6 +2319,7 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) override; }; @@ -4699,6 +4701,7 @@ dw2_expand_marked_cus (dwarf2_per_objfile *per_objfile, offset_type idx, gdb::function_view file_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, search_domain kind) { offset_type *vec, vec_len, vec_idx; @@ -4738,6 +4741,17 @@ dw2_expand_marked_cus /* Only check the symbol's kind if it has one. */ if (attrs_valid) { + if (is_static) + { + if ((search_flags & SEARCH_STATIC_BLOCK) == 0) + continue; + } + else + { + if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0) + continue; + } + switch (kind) { case VARIABLES_DOMAIN: @@ -4863,6 +4877,7 @@ dwarf2_gdb_index::expand_symtabs_matching const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); @@ -4895,7 +4910,7 @@ dwarf2_gdb_index::expand_symtabs_matching [&] (offset_type idx) { if (!dw2_expand_marked_cus (per_objfile, idx, file_matcher, - expansion_notify, kind)) + expansion_notify, search_flags, kind)) return false; return true; }, per_objfile); @@ -5373,7 +5388,7 @@ class dw2_debug_names_iterator { public: dw2_debug_names_iterator (const mapped_debug_names &map, - gdb::optional block_index, + block_search_flags block_index, domain_enum domain, const char *name, dwarf2_per_objfile *per_objfile) : m_map (map), m_block_index (block_index), m_domain (domain), @@ -5382,7 +5397,8 @@ public: {} dw2_debug_names_iterator (const mapped_debug_names &map, - search_domain search, uint32_t namei, dwarf2_per_objfile *per_objfile) + search_domain search, uint32_t namei, + dwarf2_per_objfile *per_objfile) : m_map (map), m_search (search), m_addr (find_vec_in_debug_names (map, namei, per_objfile)), @@ -5390,7 +5406,7 @@ public: {} dw2_debug_names_iterator (const mapped_debug_names &map, - block_enum block_index, domain_enum domain, + block_search_flags block_index, domain_enum domain, uint32_t namei, dwarf2_per_objfile *per_objfile) : m_map (map), m_block_index (block_index), m_domain (domain), m_addr (find_vec_in_debug_names (map, namei, per_objfile)), @@ -5411,9 +5427,9 @@ private: /* The internalized form of .debug_names. */ const mapped_debug_names &m_map; - /* If set, only look for symbols that match that block. Valid values are - GLOBAL_BLOCK and STATIC_BLOCK. */ - const gdb::optional m_block_index; + /* Restrict the search to these blocks. */ + block_search_flags m_block_index = (SEARCH_GLOBAL_BLOCK + | SEARCH_STATIC_BLOCK); /* The kind of symbol we're looking for. */ const domain_enum m_domain = UNDEF_DOMAIN; @@ -5662,13 +5678,18 @@ dw2_debug_names_iterator::next () goto again; /* Check static vs global. */ - if (symbol_linkage_ != symbol_linkage::unknown && m_block_index.has_value ()) + if (symbol_linkage_ != symbol_linkage::unknown) { - const bool want_static = *m_block_index == STATIC_BLOCK; - const bool symbol_is_static = - symbol_linkage_ == symbol_linkage::static_; - if (want_static != symbol_is_static) - goto again; + if (symbol_linkage_ == symbol_linkage::static_) + { + if ((m_block_index & SEARCH_STATIC_BLOCK) == 0) + goto again; + } + else + { + if ((m_block_index & SEARCH_GLOBAL_BLOCK) == 0) + goto again; + } } /* Match dw2_symtab_iter_next, symbol_kind @@ -5783,7 +5804,11 @@ dwarf2_debug_names_index::lookup_symbol } const auto &map = *mapp; - dw2_debug_names_iterator iter (map, block_index, domain, name, per_objfile); + 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; @@ -5845,7 +5870,10 @@ dwarf2_debug_names_index::expand_symtabs_for_function { const mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table; - dw2_debug_names_iterator iter (map, {}, VAR_DOMAIN, func_name, + dw2_debug_names_iterator iter (map, + (SEARCH_GLOBAL_BLOCK + | SEARCH_STATIC_BLOCK), + VAR_DOMAIN, func_name, per_objfile); struct dwarf2_per_cu_data *per_cu; @@ -5870,6 +5898,8 @@ dwarf2_debug_names_index::map_matching_symbols mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table; const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; + const block_search_flags block_flags + = global ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK; const char *match_name = name.ada ().lookup_name ().c_str (); auto matcher = [&] (const char *symname) @@ -5884,7 +5914,7 @@ dwarf2_debug_names_index::map_matching_symbols { /* The name was matched, now expand corresponding CUs that were marked. */ - dw2_debug_names_iterator iter (map, block_kind, domain, namei, + dw2_debug_names_iterator iter (map, block_flags, domain, namei, per_objfile); struct dwarf2_per_cu_data *per_cu; @@ -5919,6 +5949,7 @@ dwarf2_debug_names_index::expand_symtabs_matching const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); diff --git a/gdb/linespec.c b/gdb/linespec.c index 4034bbab8a0..f37861b343a 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1170,6 +1170,8 @@ iterate_over_all_matching_symtabs for (objfile *objfile : current_program_space->objfiles ()) { objfile->expand_symtabs_matching (NULL, &lookup_name, NULL, NULL, + (SEARCH_GLOBAL_BLOCK + | SEARCH_STATIC_BLOCK), search_domain); for (compunit_symtab *cu : objfile->compunits ()) diff --git a/gdb/objfiles.h b/gdb/objfiles.h index fd3323fef07..9a194c1d8d4 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -608,6 +608,7 @@ public: const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind); /* See quick_symbol_functions. */ diff --git a/gdb/psympriv.h b/gdb/psympriv.h index 51b02f586bb..70a397f8167 100644 --- a/gdb/psympriv.h +++ b/gdb/psympriv.h @@ -547,6 +547,7 @@ struct psymbol_functions : public quick_symbol_functions const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) override; struct compunit_symtab *find_pc_sect_compunit_symtab diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 6e7bf240a39..c3461168294 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1207,6 +1207,7 @@ static bool recursively_search_psymtabs (struct partial_symtab *ps, struct objfile *objfile, + block_search_flags search_flags, enum search_domain domain, const lookup_name_info &lookup_name, gdb::function_view sym_matcher) @@ -1229,8 +1230,8 @@ recursively_search_psymtabs continue; r = recursively_search_psymtabs (ps->dependencies[i], - objfile, domain, lookup_name, - sym_matcher); + objfile, search_flags, domain, + lookup_name, sym_matcher); if (r != 0) { ps->searched_flag = PST_SEARCHED_AND_FOUND; @@ -1247,11 +1248,24 @@ recursively_search_psymtabs /* Go through all of the symbols stored in a partial symtab in one loop. */ partial_symbol **psym = ps->global_psymbols.data (); + + if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0) + { + if (ps->static_psymbols.empty ()) + keep_going = 0; + else + { + psym = ps->static_psymbols.data (); + bound = sbound; + } + } + while (keep_going) { if (psym >= bound) { - if (bound == gbound && !ps->static_psymbols.empty ()) + if (bound == gbound && !ps->static_psymbols.empty () + && (search_flags & SEARCH_STATIC_BLOCK) != 0) { psym = ps->static_psymbols.data (); bound = sbound; @@ -1300,6 +1314,7 @@ psymbol_functions::expand_symtabs_matching const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain domain) { /* Clear the search flags. */ @@ -1338,7 +1353,7 @@ psymbol_functions::expand_symtabs_matching } if ((symbol_matcher == NULL && lookup_name == NULL) - || recursively_search_psymtabs (ps, objfile, domain, + || recursively_search_psymtabs (ps, objfile, search_flags, domain, *psym_lookup_name, symbol_matcher)) { diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 25b6488f1be..ead26d5d441 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -560,7 +560,9 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw) { /* Expand any symtabs that contain potentially matching symbols. */ lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - expand_symtabs_matching (NULL, lookup_name, NULL, NULL, ALL_DOMAIN); + expand_symtabs_matching (NULL, lookup_name, NULL, NULL, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, + ALL_DOMAIN); for (objfile *objfile : current_program_space->objfiles ()) { diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index 37601d8afbd..3332d329e02 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -219,6 +219,7 @@ struct quick_symbol_functions const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) = 0; /* Return the comp unit from OBJFILE that contains PC and diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index eff2e3aa337..b1763243534 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -271,6 +271,7 @@ objfile::expand_symtabs_matching const lookup_name_info *lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) { if (debug_symfile) @@ -285,7 +286,7 @@ objfile::expand_symtabs_matching for (const auto &iter : qf) if (!iter->expand_symtabs_matching (this, file_matcher, lookup_name, symbol_matcher, expansion_notify, - kind)) + search_flags, kind)) return false; return true; } diff --git a/gdb/symfile.c b/gdb/symfile.c index 3e8859916af..5f83cbf67c8 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -3722,13 +3722,16 @@ expand_symtabs_matching const lookup_name_info &lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind) { for (objfile *objfile : current_program_space->objfiles ()) if (!objfile->expand_symtabs_matching (file_matcher, &lookup_name, symbol_matcher, - expansion_notify, kind)) + expansion_notify, + search_flags, + kind)) return false; return true; } diff --git a/gdb/symfile.h b/gdb/symfile.h index 56fc37910fb..22b091182aa 100644 --- a/gdb/symfile.h +++ b/gdb/symfile.h @@ -326,6 +326,7 @@ bool expand_symtabs_matching const lookup_name_info &lookup_name, gdb::function_view symbol_matcher, gdb::function_view expansion_notify, + block_search_flags search_flags, enum search_domain kind); void map_symbol_filenames (gdb::function_view fun, diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 9ea5cb55d0f..33657f88fa9 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -938,6 +938,7 @@ maintenance_expand_symtabs (const char *args, int from_tty) NULL, NULL, NULL, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, ALL_DOMAIN); } diff --git a/gdb/symtab.c b/gdb/symtab.c index 907ebd03984..a34207fc74b 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4547,6 +4547,7 @@ global_symbol_searcher::expand_symtabs || preg->exec (symname, 0, NULL, 0) == 0); }, NULL, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, kind); /* Here, we search through the minimal symbol tables for functions and @@ -5732,6 +5733,7 @@ default_collect_symbol_completion_matches_break_on sym_text, word, code); return true; }, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, ALL_DOMAIN); /* Search upwards from currently selected frame (so that we can