[binutils-gdb] Remove quick_symbol_functions::lookup_symbol

Tom Tromey tromey@sourceware.org
Sat Apr 17 15:39:55 GMT 2021


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=84d865e39c3739097d7a3481b9c9b6b6fecb2b06

commit 84d865e39c3739097d7a3481b9c9b6b6fecb2b06
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Apr 17 09:35:04 2021 -0600

    Remove quick_symbol_functions::lookup_symbol
    
    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.
    
    gdb/ChangeLog
    2021-04-17  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.

Diff:
---
 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(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 31af446c5b6..d5cff05bda0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,17 @@
+2021-04-17  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.
+
 2021-04-17  Tom Tromey  <tom@tromey.com>
 
 	* symtab.c (global_symbol_searcher::expand_symtabs): Update.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 43d276f4736..eabe16a6528 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2265,11 +2265,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,
@@ -2296,11 +2291,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,
@@ -3667,50 +3657,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)
@@ -5794,58 +5740,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 ec64b1c3a98..31914d50a60 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -576,7 +576,16 @@ public:
     (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 25f3fe500fa..9d1375bd96a 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -511,11 +511,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 c766107504d..b9b7c7d06b2 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 4c0ef735472..6252eb5a382 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 577b0fcd86c..0535f413c07 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;
     }


More information about the Gdb-cvs mailing list