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  <tom@tromey.com>

	* 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)
	<expand_symtabs_matching>: 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) <expand_symtabs_matching>:
	Add search_flags parameter.
	* objfiles.h (struct objfile) <expand_symtabs_matching>: Add
	search_flags parameter.
	* linespec.c (iterate_over_all_matching_symtabs): Update.
	* dwarf2/read.c (struct dwarf2_gdb_index)
	<expand_symtabs_matching>: Add search_flags parameter.
	(struct dwarf2_debug_names_index) <expand_symtabs_matching>: 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.
	<m_block_index>: 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.
This commit is contained in:
Tom Tromey 2021-04-17 09:35:04 -06:00
parent df35e6262d
commit 03a8ea51c3
14 changed files with 128 additions and 23 deletions

View file

@ -1,3 +1,45 @@
2021-04-17 Tom Tromey <tom@tromey.com>
* 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)
<expand_symtabs_matching>: 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) <expand_symtabs_matching>:
Add search_flags parameter.
* objfiles.h (struct objfile) <expand_symtabs_matching>: Add
search_flags parameter.
* linespec.c (iterate_over_all_matching_symtabs): Update.
* dwarf2/read.c (struct dwarf2_gdb_index)
<expand_symtabs_matching>: Add search_flags parameter.
(struct dwarf2_debug_names_index) <expand_symtabs_matching>: 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.
<m_block_index>: 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 <tom@tromey.com>
* symtab.c (default_collect_symbol_completion_matches_break_on):

View file

@ -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

View file

@ -2289,6 +2289,7 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
const lookup_name_info *lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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<expand_symtabs_file_matcher_ftype> file_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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_enum> 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<block_enum> 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,14 +5678,19 @@ 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)
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
and debug_names::psymbol_tag. */
@ -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<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
block_search_flags search_flags,
enum search_domain kind)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);

View file

@ -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 ())

View file

@ -608,6 +608,7 @@ public:
const lookup_name_info *lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
block_search_flags search_flags,
enum search_domain kind);
/* See quick_symbol_functions. */

View file

@ -547,6 +547,7 @@ struct psymbol_functions : public quick_symbol_functions
const lookup_name_info *lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
block_search_flags search_flags,
enum search_domain kind) override;
struct compunit_symtab *find_pc_sect_compunit_symtab

View file

@ -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<expand_symtabs_symbol_matcher_ftype> 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<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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))
{

View file

@ -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 ())
{

View file

@ -219,6 +219,7 @@ struct quick_symbol_functions
const lookup_name_info *lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
block_search_flags search_flags,
enum search_domain kind) = 0;
/* Return the comp unit from OBJFILE that contains PC and

View file

@ -271,6 +271,7 @@ objfile::expand_symtabs_matching
const lookup_name_info *lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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;
}

View file

@ -3722,13 +3722,16 @@ expand_symtabs_matching
const lookup_name_info &lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> 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;
}

View file

@ -326,6 +326,7 @@ bool expand_symtabs_matching
const lookup_name_info &lookup_name,
gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
block_search_flags search_flags,
enum search_domain kind);
void map_symbol_filenames (gdb::function_view<symbol_filename_ftype> fun,

View file

@ -938,6 +938,7 @@ maintenance_expand_symtabs (const char *args, int from_tty)
NULL,
NULL,
NULL,
SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
ALL_DOMAIN);
}

View file

@ -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