[7/9] Remove quick_symbol_functions::expand_symtabs_for_function

Message ID 20210325170458.2351251-8-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 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.

2021-03-25  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       |  22 +++++++
 gdb/dwarf2/read.c   | 148 ++------------------------------------------
 gdb/objfiles.h      |   3 +-
 gdb/psympriv.h      |   3 -
 gdb/psymtab.c       |  23 -------
 gdb/quick-symbol.h  |   5 --
 gdb/symfile-debug.c |  13 +++-
 7 files changed, 41 insertions(+), 176 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8d5ef85f15b..09529cf535c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2234,9 +2234,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,
@@ -2260,9 +2257,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,
@@ -2910,68 +2904,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
@@ -3373,13 +3305,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;
@@ -3388,37 +3320,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.  */
@@ -3575,22 +3476,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)
 {
@@ -5659,29 +5544,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,
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 06628e38e88..4a170415ece 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -578,7 +578,8 @@  struct objfile
   /* 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.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index db6e85efa37..a400bc85f41 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -515,9 +515,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,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 624c3be01ce..8205dbc2923 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -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.  */
 
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 6a721e08b3f..50bcf397e2e 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -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;
 
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index b58823ffa12..97e806b659f 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -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