Remove quick_symbol_functions::expand_symtabs_for_function
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 removes quick_symbol_functions::expand_symtabs_for_function,
replacing it with a call to expand_symtabs_matching.  As with the
previous patches, the implementation is consolidated in the objfile
method.

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

* symfile-debug.c (objfile::expand_symtabs_for_function):
Rewrite.
* quick-symbol.h (struct quick_symbol_functions)
<expand_symtabs_for_function>: Remove.
* psymtab.c (psymbol_functions::expand_symtabs_for_function):
Remove.
* psympriv.h (struct psymbol_functions)
<expand_symtabs_for_function>: Remove.
* objfiles.h (struct objfile) <expand_symtabs_for_function>:
Update comment.
* dwarf2/read.c (struct dwarf2_gdb_index)
<expand_symtabs_for_function>: Remove.
(struct dwarf2_debug_names_index) <expand_symtabs_for_function>:
Remove.
(find_slot_in_mapped_hash): Remove.
(dw2_symtab_iter_init_common): Merge with dw2_symtab_iter_init.
(dw2_symtab_iter_init): Remove one overload.
(dwarf2_gdb_index::expand_symtabs_for_function)
(dwarf2_debug_names_index::expand_symtabs_for_function): 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 78e7795853a75c45213eba3bf2becb410985f96d..88e87905915a257619a815ff42663cb35dcf8a36 100644 (file)
@@ -1,3 +1,25 @@
+2021-04-17  Tom Tromey  <tom@tromey.com>
+
+       * symfile-debug.c (objfile::expand_symtabs_for_function):
+       Rewrite.
+       * quick-symbol.h (struct quick_symbol_functions)
+       <expand_symtabs_for_function>: Remove.
+       * psymtab.c (psymbol_functions::expand_symtabs_for_function):
+       Remove.
+       * psympriv.h (struct psymbol_functions)
+       <expand_symtabs_for_function>: Remove.
+       * objfiles.h (struct objfile) <expand_symtabs_for_function>:
+       Update comment.
+       * dwarf2/read.c (struct dwarf2_gdb_index)
+       <expand_symtabs_for_function>: Remove.
+       (struct dwarf2_debug_names_index) <expand_symtabs_for_function>:
+       Remove.
+       (find_slot_in_mapped_hash): Remove.
+       (dw2_symtab_iter_init_common): Merge with dw2_symtab_iter_init.
+       (dw2_symtab_iter_init): Remove one overload.
+       (dwarf2_gdb_index::expand_symtabs_for_function)
+       (dwarf2_debug_names_index::expand_symtabs_for_function): Remove.
+
 2021-04-17  Tom Tromey  <tom@tromey.com>
 
        * symfile-debug.c (objfile::map_symtabs_matching_filename):
index 763e41601dcd72255cafbc0b4e4c276bebf3e52b..007b70ec32aea8f6958f9307a57a2e09cd645e61 100644 (file)
@@ -2263,9 +2263,6 @@ struct dwarf2_gdb_index : public dwarf2_base_index_functions
 {
   void dump (struct objfile *objfile) override;
 
-  void expand_symtabs_for_function (struct objfile *objfile,
-                                   const char *func_name) override;
-
   void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
@@ -2289,9 +2286,6 @@ struct dwarf2_debug_names_index : public dwarf2_base_index_functions
 {
   void dump (struct objfile *objfile) override;
 
-  void expand_symtabs_for_function (struct objfile *objfile,
-                                   const char *func_name) override;
-
   void map_matching_symbols
     (struct objfile *,
      const lookup_name_info &lookup_name,
@@ -2939,68 +2933,6 @@ create_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
                                                 &per_bfd->obstack);
 }
 
-/* Find a slot in the mapped index INDEX for the object named NAME.
-   If NAME is found, set *VEC_OUT to point to the CU vector in the
-   constant pool and return true.  If NAME cannot be found, return
-   false.  */
-
-static bool
-find_slot_in_mapped_hash (struct mapped_index *index, const char *name,
-                         offset_type **vec_out)
-{
-  offset_type hash;
-  offset_type slot, step;
-  int (*cmp) (const char *, const char *);
-
-  gdb::unique_xmalloc_ptr<char> without_params;
-  if (current_language->la_language == language_cplus
-      || current_language->la_language == language_fortran
-      || current_language->la_language == language_d)
-    {
-      /* NAME is already canonical.  Drop any qualifiers as .gdb_index does
-        not contain any.  */
-
-      if (strchr (name, '(') != NULL)
-       {
-         without_params = cp_remove_params (name);
-
-         if (without_params != NULL)
-           name = without_params.get ();
-       }
-    }
-
-  /* Index version 4 did not support case insensitive searches.  But the
-     indices for case insensitive languages are built in lowercase, therefore
-     simulate our NAME being searched is also lowercased.  */
-  hash = mapped_index_string_hash ((index->version == 4
-                                   && case_sensitivity == case_sensitive_off
-                                   ? 5 : index->version),
-                                  name);
-
-  slot = hash & (index->symbol_table.size () - 1);
-  step = ((hash * 17) & (index->symbol_table.size () - 1)) | 1;
-  cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
-
-  for (;;)
-    {
-      const char *str;
-
-      const auto &bucket = index->symbol_table[slot];
-      if (bucket.name == 0 && bucket.vec == 0)
-       return false;
-
-      str = index->constant_pool + MAYBE_SWAP (bucket.name);
-      if (!cmp (name, str))
-       {
-         *vec_out = (offset_type *) (index->constant_pool
-                                     + MAYBE_SWAP (bucket.vec));
-         return true;
-       }
-
-      slot = (slot + step) & (index->symbol_table.size () - 1);
-    }
-}
-
 /* A helper function that reads the .gdb_index from BUFFER and fills
    in MAP.  FILENAME is the name of the file containing the data;
    it is used for error reporting.  DEPRECATED_OK is true if it is
@@ -3402,13 +3334,13 @@ struct dw2_symtab_iterator
   int global_seen;
 };
 
-/* Initialize the index symtab iterator ITER, common part.  */
+/* Initialize the index symtab iterator ITER, offset_type NAMEI variant.  */
 
 static void
-dw2_symtab_iter_init_common (struct dw2_symtab_iterator *iter,
-                            dwarf2_per_objfile *per_objfile,
-                            gdb::optional<block_enum> block_index,
-                            domain_enum domain)
+dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
+                     dwarf2_per_objfile *per_objfile,
+                     gdb::optional<block_enum> block_index,
+                     domain_enum domain, offset_type namei)
 {
   iter->per_objfile = per_objfile;
   iter->block_index = block_index;
@@ -3417,37 +3349,6 @@ dw2_symtab_iter_init_common (struct dw2_symtab_iterator *iter,
   iter->global_seen = 0;
   iter->vec = NULL;
   iter->length = 0;
-}
-
-/* Initialize the index symtab iterator ITER, const char *NAME variant.  */
-
-static void
-dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
-                     dwarf2_per_objfile *per_objfile,
-                     gdb::optional<block_enum> block_index,
-                     domain_enum domain,
-                     const char *name)
-{
-  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
-
-  mapped_index *index = per_objfile->per_bfd->index_table.get ();
-  /* index is NULL if OBJF_READNOW.  */
-  if (index == NULL)
-    return;
-
-  if (find_slot_in_mapped_hash (index, name, &iter->vec))
-    iter->length = MAYBE_SWAP (*iter->vec);
-}
-
-/* Initialize the index symtab iterator ITER, offset_type NAMEI variant.  */
-
-static void
-dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
-                     dwarf2_per_objfile *per_objfile,
-                     gdb::optional<block_enum> block_index,
-                     domain_enum domain, offset_type namei)
-{
-  dw2_symtab_iter_init_common (iter, per_objfile, block_index, domain);
 
   mapped_index *index = per_objfile->per_bfd->index_table.get ();
   /* index is NULL if OBJF_READNOW.  */
@@ -3604,22 +3505,6 @@ dwarf2_gdb_index::dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-void
-dwarf2_gdb_index::expand_symtabs_for_function (struct objfile *objfile,
-                                              const char *func_name)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  struct dw2_symtab_iterator iter;
-  struct dwarf2_per_cu_data *per_cu;
-
-  dw2_symtab_iter_init (&iter, per_objfile, {}, VAR_DOMAIN, func_name);
-
-  while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
-    dw2_instantiate_symtab (per_cu, per_objfile, false);
-
-}
-
 void
 dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
 {
@@ -5660,29 +5545,6 @@ dwarf2_debug_names_index::dump (struct objfile *objfile)
   printf_filtered ("\n");
 }
 
-void
-dwarf2_debug_names_index::expand_symtabs_for_function
-     (struct objfile *objfile, const char *func_name)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW.  */
-  if (per_objfile->per_bfd->debug_names_table)
-    {
-      const mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
-
-      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;
-      while ((per_cu = iter.next ()) != NULL)
-       dw2_instantiate_symtab (per_cu, per_objfile, false);
-    }
-}
-
 void
 dwarf2_debug_names_index::map_matching_symbols
   (struct objfile *objfile,
index cff1d8afbde811518d2ac21ff9ed1eac77baac12..64cfca41f156c97a813f35690355e15c105e5373 100644 (file)
@@ -606,7 +606,8 @@ public:
   /* See quick_symbol_functions.  */
   void dump ();
 
-  /* See quick_symbol_functions.  */
+  /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
+     the corresponding symbol tables are loaded.  */
   void expand_symtabs_for_function (const char *func_name);
 
   /* See quick_symbol_functions.  */
index 3c174472d30edf35e1e6a5f85ae2763c73df6e45..4bd6decfaa45f5ff18614ebd04d2161849b6c6f6 100644 (file)
@@ -516,9 +516,6 @@ struct psymbol_functions : public quick_symbol_functions
 
   void dump (struct objfile *objfile) override;
 
-  void expand_symtabs_for_function (struct objfile *objfile,
-                                   const char *func_name) override;
-
   void expand_all_symtabs (struct objfile *objfile) override;
 
   void expand_symtabs_with_fullname (struct objfile *objfile,
index be523a7ded05493ee4eebf5ca16fc923e0344030..8afeeb39fb7c9461d717dad7452301c11cb9a6f2 100644 (file)
@@ -892,29 +892,6 @@ psymbol_functions::dump (struct objfile *objfile)
     }
 }
 
-/* Psymtab version of expand_symtabs_for_function.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-void
-psymbol_functions::expand_symtabs_for_function (struct objfile *objfile,
-                                               const char *func_name)
-{
-  lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
-  lookup_name_info lookup_name = base_lookup.make_ignore_params ();
-
-  for (partial_symtab *ps : require_partial_symbols (objfile))
-    {
-      if (ps->readin_p (objfile))
-       continue;
-
-      if ((lookup_partial_symbol (objfile, ps, lookup_name, 1, VAR_DOMAIN)
-          != NULL)
-         || (lookup_partial_symbol (objfile, ps, lookup_name, 0, VAR_DOMAIN)
-             != NULL))
-       psymtab_to_symtab (objfile, ps);
-    }
-}
-
 /* Psymtab version of expand_all_symtabs.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
index 63aba60bb9af787b1c8a94cb099eeaf6fe3ad1f3..1aa02e9ff4ce4a5985b2006d4b502b572ff3aff0 100644 (file)
@@ -116,11 +116,6 @@ struct quick_symbol_functions
      gdb_stdout.  This is used for "maint print objfiles".  */
   virtual void dump (struct objfile *objfile) = 0;
 
-  /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
-     the corresponding symbol tables are loaded.  */
-  virtual void expand_symtabs_for_function (struct objfile *objfile,
-                                           const char *func_name) = 0;
-
   /* Read all symbol tables associated with OBJFILE.  */
   virtual void expand_all_symtabs (struct objfile *objfile) = 0;
 
index cc31fc0b42c1ceff16214154266f331867909b12..deabea4737c3ff92a96cd0235919220bf0bbd512 100644 (file)
@@ -300,8 +300,19 @@ objfile::expand_symtabs_for_function (const char *func_name)
                      "qf->expand_symtabs_for_function (%s, \"%s\")\n",
                      objfile_debug_name (this), func_name);
 
+  lookup_name_info base_lookup (func_name, symbol_name_match_type::FULL);
+  lookup_name_info lookup_name = base_lookup.make_ignore_params ();
+
   for (const auto &iter : qf)
-    iter->expand_symtabs_for_function (this, func_name);
+    iter->expand_symtabs_matching (this,
+                                  nullptr,
+                                  &lookup_name,
+                                  nullptr,
+                                  nullptr,
+                                  (SEARCH_GLOBAL_BLOCK
+                                   | SEARCH_STATIC_BLOCK),
+                                  VAR_DOMAIN,
+                                  ALL_DOMAIN);
 }
 
 void