[25/28] Convert lookup_symbol_via_quick_fns

Message ID 20250311-search-in-psyms-v1-25-d73d9be20983@tromey.com
State New
Headers
Series Search symbols via quick API |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply

Commit Message

Tom Tromey March 11, 2025, 2:13 p.m. UTC
  This converts lookup_symbol_via_quick_fns to the callback approach,
merging the search loop and the call to expand_symtabs_matching.

Note that this changes lookup_symbol_via_quick_fns to use a
best_symbol_tracker.  Before this patch there was a discrepancy here
between the two search functions.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16994
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16998
---
 gdb/symtab.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
  

Patch

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 14bc59fc2bfe6f04a22d9fb1b5bfab0f6b13c5e6..dee25051c85db6444687ead8524281bb482c03eb 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2458,11 +2458,6 @@  lookup_symbol_via_quick_fns (struct objfile *objfile,
 			     enum block_enum block_index, const char *name,
 			     const domain_search_flags domain)
 {
-  struct compunit_symtab *cust;
-  const struct blockvector *bv;
-  const struct block *block;
-  struct block_symbol result;
-
   symbol_lookup_debug_printf_v
     ("lookup_symbol_via_quick_fns (%s, %s, %s, %s)",
      objfile_debug_name (objfile),
@@ -2470,27 +2465,37 @@  lookup_symbol_via_quick_fns (struct objfile *objfile,
      name, domain_name (domain).c_str ());
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-  cust = objfile->lookup_symbol (block_index, lookup_name, domain);
-  if (cust == NULL)
+  best_symbol_tracker accum;
+  auto searcher = [&] (compunit_symtab *symtab)
+    {
+      const struct blockvector *bv = symtab->blockvector ();
+      const struct block *block = bv->block (block_index);
+      /* If the accumulator finds a best symbol, end the search by
+	 returning false; otherwise keep going by returning true.  */
+      return !accum.search (symtab, block, lookup_name, domain);
+    };
+
+  objfile->expand_symtabs_matching (nullptr, &lookup_name, nullptr,
+				    searcher,
+				    block_index == GLOBAL_BLOCK
+				    ? SEARCH_GLOBAL_BLOCK
+				    : SEARCH_STATIC_BLOCK,
+				    domain);
+  if (accum.best_symtab == nullptr)
     {
       symbol_lookup_debug_printf_v
 	("lookup_symbol_via_quick_fns (...) = NULL");
       return {};
     }
-
-  bv = cust->blockvector ();
-  block = bv->block (block_index);
-  result.symbol = block_lookup_symbol (block, lookup_name, domain);
-  if (result.symbol == NULL)
-    error_in_psymtab_expansion (block_index, name, cust);
+  if (accum.currently_best.symbol == nullptr)
+    error_in_psymtab_expansion (block_index, name, accum.best_symtab);
 
   symbol_lookup_debug_printf_v
     ("lookup_symbol_via_quick_fns (...) = %s (block %s)",
-     host_address_to_string (result.symbol),
-     host_address_to_string (block));
+     host_address_to_string (accum.currently_best.symbol),
+     host_address_to_string (accum.currently_best.block));
 
-  result.block = block;
-  return result;
+  return accum.currently_best;
 }
 
 /* See language.h.  */