Remove quick_symbol_functions::map_symtabs_matching_filename

This replaces quick_symbol_functions::map_symtabs_matching_filename
with a call to expand_symtabs_matching.  As with the previous patch,
rather than update all callers, the implementation is consolidated in
objfile::map_symtabs_matching_filename.

gdb/ChangeLog
2021-04-17  Tom Tromey  <tom@tromey.com>

	* symfile-debug.c (objfile::map_symtabs_matching_filename):
	Rewrite.
	* quick-symbol.h (struct quick_symbol_functions)
	<map_symtabs_matching_filename>: Remove.
	* psymtab.c (partial_map_expand_apply)
	(psymbol_functions::map_symtabs_matching_filename): Remove.
	* psympriv.h (struct psymbol_functions)
	<map_symtabs_matching_filename>: Remove.
	* objfiles.h (struct objfile) <map_symtabs_matching_filename>:
	Update comment.
	* dwarf2/read.c (struct dwarf2_base_index_functions)
	<map_symtabs_matching_filename>: Remove.
	(dw2_map_expand_apply)
	(dwarf2_base_index_functions::map_symtabs_matching_filename):
	Remove.
This commit is contained in:
Tom Tromey
2021-04-17 09:35:04 -06:00
parent 84d865e39c
commit 536a40f3a8
7 changed files with 77 additions and 215 deletions

View File

@ -1,3 +1,21 @@
2021-04-17 Tom Tromey <tom@tromey.com>
* symfile-debug.c (objfile::map_symtabs_matching_filename):
Rewrite.
* quick-symbol.h (struct quick_symbol_functions)
<map_symtabs_matching_filename>: Remove.
* psymtab.c (partial_map_expand_apply)
(psymbol_functions::map_symtabs_matching_filename): Remove.
* psympriv.h (struct psymbol_functions)
<map_symtabs_matching_filename>: Remove.
* objfiles.h (struct objfile) <map_symtabs_matching_filename>:
Update comment.
* dwarf2/read.c (struct dwarf2_base_index_functions)
<map_symtabs_matching_filename>: Remove.
(dw2_map_expand_apply)
(dwarf2_base_index_functions::map_symtabs_matching_filename):
Remove.
2021-04-17 Tom Tromey <tom@tromey.com> 2021-04-17 Tom Tromey <tom@tromey.com>
* symfile-debug.c (objfile::lookup_symbol): Rewrite. * symfile-debug.c (objfile::lookup_symbol): Rewrite.

View File

@ -2228,10 +2228,6 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
void forget_cached_source_info (struct objfile *objfile) override; void forget_cached_source_info (struct objfile *objfile) override;
bool map_symtabs_matching_filename
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback) override;
enum language lookup_global_symbol_language (struct objfile *objfile, enum language lookup_global_symbol_language (struct objfile *objfile,
const char *name, const char *name,
domain_enum domain, domain_enum domain,
@ -3381,100 +3377,6 @@ dwarf2_base_index_functions::forget_cached_source_info
dw2_free_cached_file_names, NULL); dw2_free_cached_file_names, NULL);
} }
/* Helper function for dw2_map_symtabs_matching_filename that expands
the symtabs and calls the iterator. */
static int
dw2_map_expand_apply (struct objfile *objfile,
struct dwarf2_per_cu_data *per_cu,
const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback)
{
struct compunit_symtab *last_made = objfile->compunit_symtabs;
/* Don't visit already-expanded CUs. */
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
if (per_objfile->symtab_set_p (per_cu))
return 0;
/* This may expand more than one symtab, and we want to iterate over
all of them. */
dw2_instantiate_symtab (per_cu, per_objfile, false);
return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs,
last_made, callback);
}
/* Implementation of the map_symtabs_matching_filename method. */
bool
dwarf2_base_index_functions::map_symtabs_matching_filename
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback)
{
const char *name_basename = lbasename (name);
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
/* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */
for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
{
/* We only need to look at symtabs not already expanded. */
if (per_objfile->symtab_set_p (per_cu))
continue;
quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
if (file_data == NULL)
continue;
for (int j = 0; j < file_data->num_file_names; ++j)
{
const char *this_name = file_data->file_names[j];
const char *this_real_name;
if (compare_filenames_for_search (this_name, name))
{
if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
callback))
return true;
continue;
}
/* Before we invoke realpath, which can get expensive when many
files are involved, do a quick comparison of the basenames. */
if (! basenames_may_differ
&& FILENAME_CMP (lbasename (this_name), name_basename) != 0)
continue;
this_real_name = dw2_get_real_path (per_objfile, file_data, j);
if (compare_filenames_for_search (this_real_name, name))
{
if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
callback))
return true;
continue;
}
if (real_path != NULL)
{
gdb_assert (IS_ABSOLUTE_PATH (real_path));
gdb_assert (IS_ABSOLUTE_PATH (name));
if (this_real_name != NULL
&& FILENAME_CMP (real_path, this_real_name) == 0)
{
if (dw2_map_expand_apply (objfile, per_cu, name, real_path,
callback))
return true;
continue;
}
}
}
}
return false;
}
/* Struct used to manage iterating over all CUs looking for a symbol. */ /* Struct used to manage iterating over all CUs looking for a symbol. */
struct dw2_symtab_iterator struct dw2_symtab_iterator

View File

@ -571,7 +571,18 @@ public:
/* See quick_symbol_functions. */ /* See quick_symbol_functions. */
void forget_cached_source_info (); void forget_cached_source_info ();
/* See quick_symbol_functions. */ /* Expand and iterate over each "partial" symbol table in OBJFILE
where the source file is named NAME.
If NAME is not absolute, a match after a '/' in the symbol table's
file name will also work, REAL_PATH is NULL then. If NAME is
absolute then REAL_PATH is non-NULL absolute file name as resolved
via gdb_realpath from NAME.
If a match is found, the "partial" symbol table is expanded.
Then, this calls iterate_over_some_symtabs (or equivalent) over
all newly-created symbol tables, passing CALLBACK to it.
The result of this call is returned. */
bool map_symtabs_matching_filename bool map_symtabs_matching_filename
(const char *name, const char *real_path, (const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback); gdb::function_view<bool (symtab *)> callback);

View File

@ -507,10 +507,6 @@ struct psymbol_functions : public quick_symbol_functions
void forget_cached_source_info (struct objfile *objfile) override; void forget_cached_source_info (struct objfile *objfile) override;
bool map_symtabs_matching_filename
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback) override;
enum language lookup_global_symbol_language (struct objfile *objfile, enum language lookup_global_symbol_language (struct objfile *objfile,
const char *name, const char *name,
domain_enum domain, domain_enum domain,

View File

@ -87,96 +87,6 @@ psymbol_functions::require_partial_symbols (struct objfile *objfile)
return m_partial_symtabs->range (); return m_partial_symtabs->range ();
} }
/* Helper function for psym_map_symtabs_matching_filename that
expands the symtabs and calls the iterator. */
static bool
partial_map_expand_apply (struct objfile *objfile,
const char *name,
const char *real_path,
struct partial_symtab *pst,
gdb::function_view<bool (symtab *)> callback)
{
struct compunit_symtab *last_made = objfile->compunit_symtabs;
/* Shared psymtabs should never be seen here. Instead they should
be handled properly by the caller. */
gdb_assert (pst->user == NULL);
/* Don't visit already-expanded psymtabs. */
if (pst->readin_p (objfile))
return 0;
/* This may expand more than one symtab, and we want to iterate over
all of them. */
psymtab_to_symtab (objfile, pst);
return iterate_over_some_symtabs (name, real_path, objfile->compunit_symtabs,
last_made, callback);
}
/* Psymtab version of map_symtabs_matching_filename. See its definition in
the definition of quick_symbol_functions in symfile.h. */
bool
psymbol_functions::map_symtabs_matching_filename
(struct objfile *objfile,
const char *name,
const char *real_path,
gdb::function_view<bool (symtab *)> callback)
{
const char *name_basename = lbasename (name);
for (partial_symtab *pst : require_partial_symbols (objfile))
{
/* Anonymous psymtabs don't have a file name. */
if (pst->anonymous)
continue;
if (compare_filenames_for_search (pst->filename, name))
{
while (pst->user)
pst = pst->user;
if (partial_map_expand_apply (objfile, name, real_path,
pst, callback))
return true;
continue;
}
/* Before we invoke realpath, which can get expensive when many
files are involved, do a quick comparison of the basenames. */
if (! basenames_may_differ
&& FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
continue;
if (compare_filenames_for_search (psymtab_to_fullname (pst), name))
{
if (partial_map_expand_apply (objfile, name, real_path,
pst, callback))
return true;
continue;
}
/* If the user gave us an absolute path, try to find the file in
this symtab and use its absolute path. */
if (real_path != NULL)
{
gdb_assert (IS_ABSOLUTE_PATH (real_path));
gdb_assert (IS_ABSOLUTE_PATH (name));
if (filename_cmp (psymtab_to_fullname (pst), real_path) == 0)
{
if (partial_map_expand_apply (objfile, name, real_path,
pst, callback))
return true;
continue;
}
}
}
return false;
}
/* Find which partial symtab contains PC and SECTION starting at psymtab PST. /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */ We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */

View File

@ -93,22 +93,6 @@ struct quick_symbol_functions
/* Forget all cached full file names for OBJFILE. */ /* Forget all cached full file names for OBJFILE. */
virtual void forget_cached_source_info (struct objfile *objfile) = 0; virtual void forget_cached_source_info (struct objfile *objfile) = 0;
/* Expand and iterate over each "partial" symbol table in OBJFILE
where the source file is named NAME.
If NAME is not absolute, a match after a '/' in the symbol table's
file name will also work, REAL_PATH is NULL then. If NAME is
absolute then REAL_PATH is non-NULL absolute file name as resolved
via gdb_realpath from NAME.
If a match is found, the "partial" symbol table is expanded.
Then, this calls iterate_over_some_symtabs (or equivalent) over
all newly-created symbol tables, passing CALLBACK to it.
The result of this call is returned. */
virtual bool map_symtabs_matching_filename
(struct objfile *objfile, const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback) = 0;
/* Check to see if the global symbol is defined in a "partial" symbol table /* 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 of OBJFILE. NAME is the name of the symbol to look for. DOMAIN
indicates what sort of symbol to search for. indicates what sort of symbol to search for.

View File

@ -33,6 +33,7 @@
#include "symtab.h" #include "symtab.h"
#include "symfile.h" #include "symfile.h"
#include "block.h" #include "block.h"
#include "filenames.h"
/* We need to save a pointer to the real symbol functions. /* 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 Plus, the debug versions are malloc'd because we have to NULL out the
@ -146,13 +147,51 @@ objfile::map_symtabs_matching_filename
real_path ? real_path : NULL, real_path ? real_path : NULL,
host_address_to_string (&callback)); host_address_to_string (&callback));
bool retval = false; bool retval = true;
const char *name_basename = lbasename (name);
auto match_one_filename = [&] (const char *filename, bool basenames)
{
if (compare_filenames_for_search (filename, name))
return true;
if (basenames && FILENAME_CMP (name_basename, filename) == 0)
return true;
if (real_path != nullptr && IS_ABSOLUTE_PATH (filename)
&& IS_ABSOLUTE_PATH (real_path))
return filename_cmp (filename, real_path) == 0;
return false;
};
compunit_symtab *last_made = this->compunit_symtabs;
auto on_expansion = [&] (compunit_symtab *symtab)
{
/* The callback to iterate_over_some_symtabs returns false to keep
going and true to continue, so we have to invert the result
here, for expand_symtabs_matching. */
bool result = !iterate_over_some_symtabs (name, real_path,
this->compunit_symtabs,
last_made,
callback);
last_made = this->compunit_symtabs;
return result;
};
for (const auto &iter : qf) for (const auto &iter : qf)
{ {
retval = (iter->map_symtabs_matching_filename if (!iter->expand_symtabs_matching (this,
(this, name, real_path, callback)); match_one_filename,
if (retval) nullptr,
break; nullptr,
on_expansion,
(SEARCH_GLOBAL_BLOCK
| SEARCH_STATIC_BLOCK),
UNDEF_DOMAIN,
ALL_DOMAIN))
{
retval = false;
break;
}
} }
if (debug_symfile) if (debug_symfile)
@ -160,7 +199,9 @@ objfile::map_symtabs_matching_filename
"qf->map_symtabs_matching_filename (...) = %d\n", "qf->map_symtabs_matching_filename (...) = %d\n",
retval); retval);
return retval; /* We must re-invert the return value here to match the caller's
expectations. */
return !retval;
} }
struct compunit_symtab * struct compunit_symtab *