]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: change search_symtab helper to be a method
authorJan Vrany <jan.vrany@labware.com>
Mon, 17 Nov 2025 10:15:28 +0000 (10:15 +0000)
committerJan Vrany <jan.vrany@labware.com>
Mon, 17 Nov 2025 10:15:28 +0000 (10:15 +0000)
This commit changes search_symtab helper in find_symbol_at_address to
be a method.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/block.c
gdb/block.h
gdb/symtab.c
gdb/symtab.h

index c518f6c4f17faf4cd120276a13e96c27f9ceb928..9fb04635975e370a01cbf85c7e2439715b9e91f9 100644 (file)
@@ -840,6 +840,25 @@ blockvector::contains (CORE_ADDR addr) const
   return lookup (addr) != nullptr;
 }
 
+/* See block.h.  */
+
+struct symbol *
+blockvector::symbol_at_address (CORE_ADDR addr) const
+{
+  for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
+    {
+      const struct block *b = block (i);
+
+      for (struct symbol *sym : block_iterator_range (b))
+       {
+         if (sym->loc_class () == LOC_STATIC && sym->value_address () == addr)
+           return sym;
+       }
+    }
+
+  return nullptr;
+}
+
 blockvector::~blockvector ()
 {
   for (struct block *bl : m_blocks)
index f12e9d162638d34c88f93c23da8ae0446ba847c6..df03231ca4cae4b67c20d8297da1c0bff509554a 100644 (file)
@@ -509,6 +509,10 @@ struct blockvector
   /* Return true if the blockvector contains ADDR, false otherwise.  */
   bool contains (CORE_ADDR addr) const;
 
+  /* Return symbol at ADDR or NULL if no symbol is found.  Only exact matches
+     for ADDR are considered.  */
+  struct symbol *symbol_at_address (CORE_ADDR addr) const;
+
 private:
   /* An address map mapping addresses to blocks in this blockvector.
      This pointer is zero if the blocks' start and end addresses are
index 1d9a06a52f3a6b96ec497dd21e5ff8dbeb31398f..070d94980349e75e8c4d6ce9e944a40cc16541d3 100644 (file)
@@ -505,6 +505,14 @@ compunit_symtab::forget_cached_source_info ()
 
 /* See symtab.h.  */
 
+struct symbol *
+compunit_symtab::symbol_at_address (CORE_ADDR addr) const
+{
+  return blockvector ()->symbol_at_address (addr);
+}
+
+/* See symtab.h.  */
+
 compunit_symtab::compunit_symtab (struct objfile *objfile,
                                  const char *name_)
   : m_objfile (objfile),
@@ -2831,26 +2839,6 @@ find_compunit_symtab_for_pc (CORE_ADDR pc)
 struct symbol *
 find_symbol_at_address (CORE_ADDR address)
 {
-  /* A helper function to search a given symtab for a symbol matching
-     ADDR.  */
-  auto search_symtab = [] (compunit_symtab *symtab, CORE_ADDR addr) -> symbol *
-    {
-      const struct blockvector *bv = symtab->blockvector ();
-
-      for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
-       {
-         const struct block *b = bv->block (i);
-
-         for (struct symbol *sym : block_iterator_range (b))
-           {
-             if (sym->loc_class () == LOC_STATIC
-                 && sym->value_address () == addr)
-               return sym;
-           }
-       }
-      return nullptr;
-    };
-
   for (objfile &objfile : current_program_space->objfiles ())
     {
       /* If this objfile was read with -readnow, then we need to
@@ -2859,7 +2847,8 @@ find_symbol_at_address (CORE_ADDR address)
        {
          for (compunit_symtab &symtab : objfile.compunits ())
            {
-             struct symbol *sym = search_symtab (&symtab, address);
+             struct symbol *sym
+               = symtab.symbol_at_address (address);
              if (sym != nullptr)
                return sym;
            }
@@ -2870,7 +2859,7 @@ find_symbol_at_address (CORE_ADDR address)
            = objfile.find_compunit_symtab_by_address (address);
          if (symtab != NULL)
            {
-             struct symbol *sym = search_symtab (symtab, address);
+             struct symbol *sym = symtab->symbol_at_address (address);
              if (sym != nullptr)
                return sym;
            }
index 9c7fe0fbf1abf93d26a70dd53c1e5b429c3a8697..845c49e057db19a7afd8cbe09028092802ae5cf6 100644 (file)
@@ -1963,6 +1963,10 @@ struct compunit_symtab : intrusive_list_node<compunit_symtab>
   /* Clear any cached source file names.  */
   void forget_cached_source_info ();
 
+  /* Return symbol at ADDR or NULL if no symbol is found.  Only exact matches
+     for ADDR are considered.  */
+  struct symbol *symbol_at_address (CORE_ADDR addr) const;
+
   /* Object file from which this symtab information was read.  */
   struct objfile *m_objfile;