[5/9] Remove quick_symbol_functions::lookup_symbol

Message ID 20210325170458.2351251-6-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, replacing it with calls to
expand_symtabs_matching.  Because the replacement is somewhat verbose,
objfile::lookup_symbol is not removed.  This consolidates some
duplicated code into this one spot.

2021-03-25  Tom Tromey  <tom@tromey.com>

	* symfile-debug.c (objfile::lookup_symbol): Rewrite.
	* quick-symbol.h (struct quick_symbol_functions) <lookup_symbol>:
	Remove.
	* psymtab.c (psymbol_functions::lookup_symbol): Remove.
	* psympriv.h (struct psymbol_functions) <lookup_symbol>: Remove.
	* objfiles.h (struct objfile) <lookup_symbol>: Add comment.
	* dwarf2/read.c (struct dwarf2_gdb_index) <lookup_symbol>:
	Remove.
	(struct dwarf2_debug_names_index) <lookup_symbol>: Remove.
	(dwarf2_gdb_index::lookup_symbol)
	(dwarf2_debug_names_index::lookup_symbol): Remove.
---
 gdb/ChangeLog       |  14 ++++++
 gdb/dwarf2/read.c   | 106 --------------------------------------------
 gdb/objfiles.h      |  11 ++++-
 gdb/psympriv.h      |   5 ---
 gdb/psymtab.c       |  51 ---------------------
 gdb/quick-symbol.h  |  15 -------
 gdb/symfile-debug.c |  44 +++++++++++++++++-
 7 files changed, 66 insertions(+), 180 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 195def9d355..5274e31b591 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2236,11 +2236,6 @@  struct dwarf2_base_index_functions : public quick_symbol_functions
 
 struct dwarf2_gdb_index : public dwarf2_base_index_functions
 {
-  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-					 block_enum block_index,
-					 const char *name,
-					 domain_enum domain) override;
-
   void dump (struct objfile *objfile) override;
 
   void expand_symtabs_for_function (struct objfile *objfile,
@@ -2267,11 +2262,6 @@  struct dwarf2_gdb_index : public dwarf2_base_index_functions
 
 struct dwarf2_debug_names_index : public dwarf2_base_index_functions
 {
-  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-					 block_enum block_index,
-					 const char *name,
-					 domain_enum domain) override;
-
   void dump (struct objfile *objfile) override;
 
   void expand_symtabs_for_function (struct objfile *objfile,
@@ -3638,50 +3628,6 @@  dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
   return NULL;
 }
 
-struct compunit_symtab *
-dwarf2_gdb_index::lookup_symbol (struct objfile *objfile,
-				 block_enum block_index,
-				 const char *name, domain_enum domain)
-{
-  struct compunit_symtab *stab_best = NULL;
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
-  struct dw2_symtab_iterator iter;
-  struct dwarf2_per_cu_data *per_cu;
-
-  dw2_symtab_iter_init (&iter, per_objfile, block_index, domain, name);
-
-  while ((per_cu = dw2_symtab_iter_next (&iter)) != NULL)
-    {
-      struct symbol *sym, *with_opaque = NULL;
-      struct compunit_symtab *stab
-	= dw2_instantiate_symtab (per_cu, per_objfile, false);
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-      const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-      sym = block_find_symbol (block, name, domain,
-			       block_find_non_opaque_type_preferred,
-			       &with_opaque);
-
-      /* Some caution must be observed with overloaded functions
-	 and methods, since the index will not contain any overload
-	 information (but NAME might contain it).  */
-
-      if (sym != NULL
-	  && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
-	return stab;
-      if (with_opaque != NULL
-	  && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
-	stab_best = stab;
-
-      /* Keep looking through other CUs.  */
-    }
-
-  return stab_best;
-}
-
 void
 dwarf2_base_index_functions::print_stats (struct objfile *objfile,
 					  bool print_bcache)
@@ -5793,58 +5739,6 @@  dw2_debug_names_iterator::next ()
   return per_cu;
 }
 
-struct compunit_symtab *
-dwarf2_debug_names_index::lookup_symbol
-     (struct objfile *objfile, block_enum block_index,
-      const char *name, domain_enum domain)
-{
-  dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-
-  const auto &mapp = per_objfile->per_bfd->debug_names_table;
-  if (!mapp)
-    {
-      /* index is NULL if OBJF_READNOW.  */
-      return NULL;
-    }
-  const auto &map = *mapp;
-
-  dw2_debug_names_iterator iter (map,
-				 block_index == GLOBAL_BLOCK
-				 ? SEARCH_GLOBAL_BLOCK
-				 : SEARCH_STATIC_BLOCK,
-				 domain, name, per_objfile);
-
-  struct compunit_symtab *stab_best = NULL;
-  struct dwarf2_per_cu_data *per_cu;
-  while ((per_cu = iter.next ()) != NULL)
-    {
-      struct symbol *sym, *with_opaque = NULL;
-      compunit_symtab *stab
-	= dw2_instantiate_symtab (per_cu, per_objfile, false);
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-      const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-      sym = block_find_symbol (block, name, domain,
-			       block_find_non_opaque_type_preferred,
-			       &with_opaque);
-
-      /* Some caution must be observed with overloaded functions and
-	 methods, since the index will not contain any overload
-	 information (but NAME might contain it).  */
-
-      if (sym != NULL
-	  && strcmp_iw (sym->search_name (), name) == 0)
-	return stab;
-      if (with_opaque != NULL
-	  && strcmp_iw (with_opaque->search_name (), name) == 0)
-	stab_best = stab;
-
-      /* Keep looking through other CUs.  */
-    }
-
-  return stab_best;
-}
-
 /* This dumps minimal information about .debug_names.  It is called
    via "mt print objfiles".  The gdb.dwarf2/gdb-index.exp testcase
    uses this to verify that .debug_names has been loaded.  */
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 22e7d7d84e1..bc3ad7bcdef 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -548,7 +548,16 @@  struct objfile
     (const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback);
 
-  /* See quick_symbol_functions.  */
+  /* Check to see if the symbol is defined in a "partial" symbol table
+     of this objfile.  BLOCK_INDEX should be either GLOBAL_BLOCK or
+     STATIC_BLOCK, depending on whether we want to search global
+     symbols or static symbols.  NAME is the name of the symbol to
+     look for.  DOMAIN indicates what sort of symbol to search for.
+
+     Returns the newly-expanded compunit in which the symbol is
+     defined, or NULL if no such symbol table exists.  If OBJFILE
+     contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
+     only TYPE_OPAQUE symbol(s), return at least that compunit.  */
   struct compunit_symtab *lookup_symbol (block_enum kind, const char *name,
 					 domain_enum domain);
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index ff3157c6691..c4e484481ea 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -510,11 +510,6 @@  struct psymbol_functions : public quick_symbol_functions
     (struct objfile *objfile, const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback) override;
 
-  struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-					 block_enum block_index,
-					 const char *name,
-					 domain_enum domain) 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 a1df7c777fe..ad7d06087d2 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -432,57 +432,6 @@  find_pc_sect_psymbol (struct objfile *objfile,
   return best;
 }
 
-/* Psymtab version of lookup_symbol.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-struct compunit_symtab *
-psymbol_functions::lookup_symbol (struct objfile *objfile,
-				  block_enum block_index, const char *name,
-				  const domain_enum domain)
-{
-  const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
-  struct compunit_symtab *stab_best = NULL;
-
-  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-
-  lookup_name_info psym_lookup_name = lookup_name.make_ignore_params ();
-
-  for (partial_symtab *ps : require_partial_symbols (objfile))
-    {
-      if (!ps->readin_p (objfile)
-	  && lookup_partial_symbol (objfile, ps, psym_lookup_name,
-				    psymtab_index, domain))
-	{
-	  struct symbol *sym, *with_opaque = NULL;
-	  struct compunit_symtab *stab = psymtab_to_symtab (objfile, ps);
-	  /* Note: While psymtab_to_symtab can return NULL if the
-	     partial symtab is empty, we can assume it won't here
-	     because lookup_partial_symbol succeeded.  */
-	  const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
-	  const struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
-
-	  sym = block_find_symbol (block, name, domain,
-				   block_find_non_opaque_type_preferred,
-				   &with_opaque);
-
-	  /* Some caution must be observed with overloaded functions
-	     and methods, since the index will not contain any overload
-	     information (but NAME might contain it).  */
-
-	  if (sym != NULL
-	      && SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
-	    return stab;
-	  if (with_opaque != NULL
-	      && SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
-	    stab_best = stab;
-
-	  /* Keep looking through other psymtabs.  */
-	}
-    }
-
-  return stab_best;
-}
-
 /* Psymtab version of lookup_global_symbol_language.  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 822e3643566..4886b9e8842 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -109,21 +109,6 @@  struct quick_symbol_functions
     (struct objfile *objfile, const char *name, const char *real_path,
      gdb::function_view<bool (symtab *)> callback) = 0;
 
-  /* Check to see if the symbol is defined in a "partial" symbol table
-     of OBJFILE.  BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
-     depending on whether we want to search global symbols or static
-     symbols.  NAME is the name of the symbol to look for.  DOMAIN
-     indicates what sort of symbol to search for.
-
-     Returns the newly-expanded compunit in which the symbol is
-     defined, or NULL if no such symbol table exists.  If OBJFILE
-     contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
-     only TYPE_OPAQUE symbol(s), return at least that compunit.  */
-  virtual struct compunit_symtab *lookup_symbol (struct objfile *objfile,
-						 block_enum block_index,
-						 const char *name,
-						 domain_enum domain) = 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 1e8cd549764..2a1c366ddcc 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -32,6 +32,7 @@ 
 #include "source.h"
 #include "symtab.h"
 #include "symfile.h"
+#include "block.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
@@ -173,10 +174,49 @@  objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 		      objfile_debug_name (this), kind, name,
 		      domain_name (domain));
 
+  lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+
+  auto search_one_symtab = [&] (compunit_symtab *stab)
+  {
+    struct symbol *sym, *with_opaque = NULL;
+    const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (stab);
+    const struct block *block = BLOCKVECTOR_BLOCK (bv, kind);
+
+    sym = block_find_symbol (block, name, domain,
+			     block_find_non_opaque_type_preferred,
+			     &with_opaque);
+
+    /* Some caution must be observed with overloaded functions
+       and methods, since the index will not contain any overload
+       information (but NAME might contain it).  */
+
+    if (sym != NULL
+	&& SYMBOL_MATCHES_SEARCH_NAME (sym, lookup_name))
+      {
+	retval = stab;
+	/* Found it.  */
+	return false;
+      }
+    if (with_opaque != NULL
+	&& SYMBOL_MATCHES_SEARCH_NAME (with_opaque, lookup_name))
+      retval = stab;
+
+    /* Keep looking through other psymtabs.  */
+    return true;
+  };
+
   for (const auto &iter : qf)
     {
-      retval = iter->lookup_symbol (this, kind, name, domain);
-      if (retval != nullptr)
+      if (!iter->expand_symtabs_matching (this,
+					  nullptr,
+					  &lookup_name,
+					  nullptr,
+					  search_one_symtab,
+					  kind == GLOBAL_BLOCK
+					  ? SEARCH_GLOBAL_BLOCK
+					  : SEARCH_STATIC_BLOCK,
+					  domain,
+					  ALL_DOMAIN))
 	break;
     }