Remove quick_symbol_functions::map_symtabs_matching_filename
authorTom Tromey <tom@tromey.com>
Sat, 17 Apr 2021 15:35:04 +0000 (09:35 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 17 Apr 2021 15:35:06 +0000 (09:35 -0600)
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.

gdb/ChangeLog
gdb/dwarf2/read.c
gdb/objfiles.h
gdb/psympriv.h
gdb/psymtab.c
gdb/quick-symbol.h
gdb/symfile-debug.c

index d5cff05bda0aefa1c7bfa02d81444ea736aeca88..78e7795853a75c45213eba3bf2becb410985f96d 100644 (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>
 
        * symfile-debug.c (objfile::lookup_symbol): Rewrite.
index eabe16a652857df9e2ff408e204fcfaaafdc7829..763e41601dcd72255cafbc0b4e4c276bebf3e52b 100644 (file)
@@ -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
index 31914d50a60ff2d661eb691b08c8b92a5c4c2d74..cff1d8afbde811518d2ac21ff9ed1eac77baac12 100644 (file)
@@ -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);
index 9d1375bd96a4f9fd3d5baece5944c58bdcb962f7..3c174472d30edf35e1e6a5f85ae2763c73df6e45 100644 (file)
@@ -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,
index b9b7c7d06b246aed127f243089d1fdb06637db46..be523a7ded05493ee4eebf5ca16fc923e0344030 100644 (file)
@@ -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.  */
 
index 6252eb5a382742b3bdc9be18a767b324148c585d..63aba60bb9af787b1c8a94cb099eeaf6fe3ad1f3 100644 (file)
@@ -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.
index 0535f413c0789f5154eb3ce105fb78777de8e91c..cc31fc0b42c1ceff16214154266f331867909b12 100644 (file)
@@ -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 *