aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-04-17 09:35:04 -0600
committerTom Tromey <tom@tromey.com>2021-04-17 09:35:06 -0600
commit536a40f3a8d2c18aae18a9137b838ff2accdfc08 (patch)
treed498eab42e09269d72816d31091eb55e083cc1b1
parent84d865e39c3739097d7a3481b9c9b6b6fecb2b06 (diff)
downloadgdb-536a40f3a8d2c18aae18a9137b838ff2accdfc08.zip
gdb-536a40f3a8d2c18aae18a9137b838ff2accdfc08.tar.gz
gdb-536a40f3a8d2c18aae18a9137b838ff2accdfc08.tar.bz2
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.
-rw-r--r--gdb/ChangeLog18
-rw-r--r--gdb/dwarf2/read.c98
-rw-r--r--gdb/objfiles.h13
-rw-r--r--gdb/psympriv.h4
-rw-r--r--gdb/psymtab.c90
-rw-r--r--gdb/quick-symbol.h16
-rw-r--r--gdb/symfile-debug.c53
7 files changed, 77 insertions, 215 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d5cff05..78e7795 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,23 @@
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>
+
* symfile-debug.c (objfile::lookup_symbol): Rewrite.
* quick-symbol.h (struct quick_symbol_functions) <lookup_symbol>:
Remove.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index eabe16a..763e416 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2228,10 +2228,6 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
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,
const char *name,
domain_enum domain,
@@ -3381,100 +3377,6 @@ dwarf2_base_index_functions::forget_cached_source_info
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 dw2_symtab_iterator
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 31914d5..cff1d8a 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -571,7 +571,18 @@ public:
/* See quick_symbol_functions. */
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
(const char *name, const char *real_path,
gdb::function_view<bool (symtab *)> callback);
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 9d1375b..3c17447 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -507,10 +507,6 @@ struct psymbol_functions : public quick_symbol_functions
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,
const char *name,
domain_enum domain,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index b9b7c7d..be523a7 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -87,96 +87,6 @@ psymbol_functions::require_partial_symbols (struct objfile *objfile)
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.
We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 6252eb5..63aba60 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -93,22 +93,6 @@ struct quick_symbol_functions
/* Forget all cached full file names for OBJFILE. */
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
of OBJFILE. NAME is the name of the symbol to look for. DOMAIN
indicates what sort of symbol to search for.
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 0535f41..cc31fc0 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -33,6 +33,7 @@
#include "symtab.h"
#include "symfile.h"
#include "block.h"
+#include "filenames.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
@@ -146,13 +147,51 @@ objfile::map_symtabs_matching_filename
real_path ? real_path : NULL,
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)
{
- retval = (iter->map_symtabs_matching_filename
- (this, name, real_path, callback));
- if (retval)
- break;
+ if (!iter->expand_symtabs_matching (this,
+ match_one_filename,
+ nullptr,
+ nullptr,
+ on_expansion,
+ (SEARCH_GLOBAL_BLOCK
+ | SEARCH_STATIC_BLOCK),
+ UNDEF_DOMAIN,
+ ALL_DOMAIN))
+ {
+ retval = false;
+ break;
+ }
}
if (debug_symfile)
@@ -160,7 +199,9 @@ objfile::map_symtabs_matching_filename
"qf->map_symtabs_matching_filename (...) = %d\n",
retval);
- return retval;
+ /* We must re-invert the return value here to match the caller's
+ expectations. */
+ return !retval;
}
struct compunit_symtab *