]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: change find_compunit_symtab_by_address to find_symbol_by_address
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 objfile::find_compunit_symtab_by_address and
corresponding quick_symbol_functions::find_compunit_symtab_by_address
to find_symbol_by_address return symbol.

This will allow simplifying find_symbol_at_address (the only caller of
find_compunit_symtab_by_address) by removing the special-case for
-readnow and moving the logic down to readnow_functions.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/cooked-index.h
gdb/dwarf2/read.c
gdb/dwarf2/read.h
gdb/objfiles.h
gdb/psymtab.h
gdb/quick-symbol.h
gdb/symfile-debug.c
gdb/symtab.c

index 8d11430dd8d6c27ea62f88baaa5704de4c84c9c8..f9ac4519b6f4cc3da3ab057176117cf53c98b91e 100644 (file)
@@ -196,7 +196,7 @@ struct cooked_index_functions : public dwarf2_base_index_functions
     return table;
   }
 
-  struct compunit_symtab *find_compunit_symtab_by_address
+  struct symbol *find_symbol_by_address
     (struct objfile *objfile, CORE_ADDR address) override;
 
   bool has_unexpanded_symtabs (struct objfile *objfile) override
index 29f100b7638248f60afb30b5e7ab42f085088fd7..7a2564c20a4bd3524568c6195c3bb1c9a6a3cbe8 100644 (file)
@@ -14556,8 +14556,8 @@ cutu_reader::read_toplevel_die (gdb::array_view<attribute *> extra_attrs)
   return die;
 }
 
-struct compunit_symtab *
-cooked_index_functions::find_compunit_symtab_by_address
+struct symbol *
+cooked_index_functions::find_symbol_by_address
      (struct objfile *objfile, CORE_ADDR address)
 {
   if (objfile->sect_index_data == -1)
@@ -14572,7 +14572,9 @@ cooked_index_functions::find_compunit_symtab_by_address
   if (per_cu == nullptr)
     return nullptr;
 
-  return dw2_instantiate_symtab (per_cu, per_objfile, false);
+  struct compunit_symtab *cu = dw2_instantiate_symtab (per_cu, per_objfile,
+                                                      false);
+  return cu->symbol_at_address (address);
 }
 
 bool
index 95f00e617c7aa2cc431979deba911f6ee6d8331b..992d60528cd04bc04e30750bfa1199e9865390ed 100644 (file)
@@ -1219,7 +1219,7 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
      CORE_ADDR pc, struct obj_section *section, int warn_if_readin)
        override;
 
-  struct compunit_symtab *find_compunit_symtab_by_address
+  struct symbol *find_symbol_by_address
     (struct objfile *objfile, CORE_ADDR address) override
   {
     return nullptr;
index 35ef6035bc70475352f04e8629cd721710263d68..31651c4ee57643acf902f4ac18d17ef431c14ca3 100644 (file)
@@ -640,7 +640,7 @@ public:
   void compute_main_name ();
 
   /* See quick_symbol_functions.  */
-  struct compunit_symtab *find_compunit_symtab_by_address (CORE_ADDR address);
+  struct symbol *find_symbol_by_address (CORE_ADDR address);
 
   /* See quick_symbol_functions.  */
   enum language lookup_global_symbol_language (const char *name,
index ab4173ddc3fedf97cd2537b9fb9c44ea33437e44..8a66f99754cd6b8016e4604d245575e155197a01 100644 (file)
@@ -642,7 +642,7 @@ struct psymbol_functions : public quick_symbol_functions
     (struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
      struct obj_section *section, int warn_if_readin) override;
 
-  struct compunit_symtab *find_compunit_symtab_by_address
+  struct symbol *find_symbol_by_address
     (struct objfile *objfile, CORE_ADDR address) override
   {
     return nullptr;
index 34dc60bc2c24014b17e01555cd13978574522be4..4ac1067e96d04a201a512d9759b1b852ee627dbb 100644 (file)
@@ -176,12 +176,10 @@ struct quick_symbol_functions
     (struct objfile *objfile, bound_minimal_symbol msymbol, CORE_ADDR pc,
      struct obj_section *section, int warn_if_readin) = 0;
 
-  /* Return the comp unit from OBJFILE that contains a symbol at
-     ADDRESS.  Return NULL if there is no such comp unit.  Unlike
-     find_pc_sect_compunit_symtab, any sort of symbol (not just text
-     symbols) can be considered, and only exact address matches are
-     considered.  */
-  virtual struct compunit_symtab *find_compunit_symtab_by_address
+  /* Return the symbol from OBJFILE at ADDRESS.  Return NULL if there is
+     no such symbol.  Any sort of symbol (not just text symbols) can be
+     considered, and only exact address matches are considered.  */
+  virtual struct symbol *find_symbol_by_address
     (struct objfile *objfile, CORE_ADDR address) = 0;
 
   /* Call FUN for every file defined in OBJFILE whose symtab is
index e5ea72649976e2830a7dae4f56cc8c0ca58ee6ae..68dbc9eca4298684ace203b9ec66aca967af76e3 100644 (file)
@@ -480,28 +480,28 @@ objfile::compute_main_name ()
     iter->compute_main_name (this);
 }
 
-struct compunit_symtab *
-objfile::find_compunit_symtab_by_address (CORE_ADDR address)
+struct symbol *
+objfile::find_symbol_by_address (CORE_ADDR address)
 {
   if (debug_symfile)
     gdb_printf (gdb_stdlog,
-               "qf->find_compunit_symtab_by_address (%s, %s)\n",
+               "qf->find_symbol_by_address (%s, %s)\n",
                objfile_debug_name (this),
                hex_string (address));
 
-  struct compunit_symtab *result = NULL;
+  struct symbol *result = NULL;
   for (const auto &iter : qf)
     {
-      result = iter->find_compunit_symtab_by_address (this, address);
+      result = iter->find_symbol_by_address (this, address);
       if (result != nullptr)
        break;
     }
 
   if (debug_symfile)
     gdb_printf (gdb_stdlog,
-               "qf->find_compunit_symtab_by_address (...) = %s\n",
+               "qf->find_symbol_by_address (...) = %s\n",
                result
-               ? debug_symtab_name (result->primary_filetab ())
+               ? result->print_name ()
                : "NULL");
 
   return result;
index 070d94980349e75e8c4d6ce9e944a40cc16541d3..2634e8fe5c2c54ddc4be8823651132c220566f1a 100644 (file)
@@ -2855,14 +2855,9 @@ find_symbol_at_address (CORE_ADDR address)
        }
       else
        {
-         struct compunit_symtab *symtab
-           = objfile.find_compunit_symtab_by_address (address);
-         if (symtab != NULL)
-           {
-             struct symbol *sym = symtab->symbol_at_address (address);
-             if (sym != nullptr)
-               return sym;
-           }
+         struct symbol *sym = objfile.find_symbol_by_address (address);
+         if (sym != nullptr)
+           return sym;
        }
     }