Remove quick_symbol_functions::lookup_symbol
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:05 +0000 (09:35 -0600)
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.

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

index 31af446c5b611a8558380666f5942f4ee6398825..d5cff05bda0aefa1c7bfa02d81444ea736aeca88 100644 (file)
@@ -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.
index 43d276f47360447bfe36bae4a10ecfa462a52ec4..eabe16a652857df9e2ff408e204fcfaaafdc7829 100644 (file)
@@ -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.  */
index ec64b1c3a9838e388481d9e4a1c82711c9cbde81..31914d50a60ff2d661eb691b08c8b92a5c4c2d74 100644 (file)
@@ -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);
 
index 25f3fe500fa2c7dc8705ff19093a6fec00c3f3ab..9d1375bd96a4f9fd3d5baece5944c58bdcb962f7 100644 (file)
@@ -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,
index c766107504d13eb049a4b221c1d228cf8bacf2af..b9b7c7d06b246aed127f243089d1fdb06637db46 100644 (file)
@@ -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.  */
 
index 4c0ef73547278a0a97049097af86f46cf3c77861..6252eb5a382742b3bdc9be18a767b324148c585d 100644 (file)
@@ -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.
index 577b0fcd86c576c79b31db50811ed4014317c199..0535f413c0789f5154eb3ce105fb78777de8e91c 100644 (file)
@@ -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;
     }