[6/9] Remove quick_symbol_functions::map_symtabs_matching_filename

Message ID 20210325170458.2351251-7-tom@tromey.com
State New
Headers show
Series
  • Simplify quick_symbol_functions
Related show

Commit Message

Tom Tromey March 25, 2021, 5:04 p.m.
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.

2021-03-25  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.
---
 gdb/ChangeLog       | 18 +++++++++
 gdb/dwarf2/read.c   | 98 ---------------------------------------------
 gdb/objfiles.h      | 13 +++++-
 gdb/psympriv.h      |  4 --
 gdb/psymtab.c       | 90 -----------------------------------------
 gdb/quick-symbol.h  | 16 --------
 gdb/symfile-debug.c | 53 +++++++++++++++++++++---
 7 files changed, 77 insertions(+), 215 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5274e31b591..8d5ef85f15b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2199,10 +2199,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,
@@ -3352,100 +3348,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 bc3ad7bcdef..06628e38e88 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -543,7 +543,18 @@  struct objfile
   /* 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 c4e484481ea..db6e85efa37 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -506,10 +506,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 ad7d06087d2..624c3be01ce 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 4886b9e8842..6a721e08b3f 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 2a1c366ddcc..b58823ffa12 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 *