[PATCH 6/7] gdb: add program_space parameter to lookup_minimal_symbol_linkage

Simon Marchi simon.marchi@polymtl.ca
Wed Jul 17 03:52:04 GMT 2024


Make the current_program_space reference bubble up one level.

Change-Id: Ic349dc96b7d375ad7c66022d84657136f0de8c87
---
 gdb/dwarf2/ada-imported.c |  4 +++-
 gdb/minsyms.c             |  5 +++--
 gdb/minsyms.h             |  6 +++---
 gdb/symtab.c              | 11 +++++++----
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c
index 9ec0d51e9205..eabbab181c97 100644
--- a/gdb/dwarf2/ada-imported.c
+++ b/gdb/dwarf2/ada-imported.c
@@ -20,6 +20,7 @@
 #include "symtab.h"
 #include "value.h"
 #include "dwarf2/loc.h"
+#include "objfiles.h"
 
 /* Helper to get the imported symbol's real name.  */
 static const char *
@@ -34,7 +35,8 @@ static struct value *
 ada_imported_read_variable (struct symbol *symbol, const frame_info_ptr &frame)
 {
   const char *name = get_imported_name (symbol);
-  bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (name, false);
+  bound_minimal_symbol minsym
+    = lookup_minimal_symbol_linkage (symbol->objfile ()->pspace (), name, false);
   if (minsym.minsym == nullptr)
     error (_("could not find imported name %s"), name);
   return value_at (symbol->type (), minsym.value_address ());
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 1670491a24ef..9c39749cbf76 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -584,9 +584,10 @@ lookup_minimal_symbol_linkage (const char *name, struct objfile *objf)
 /* See minsyms.h.  */
 
 bound_minimal_symbol
-lookup_minimal_symbol_linkage (const char *name, bool only_main)
+lookup_minimal_symbol_linkage (program_space *pspace, const char *name,
+			       bool only_main)
 {
-  for (objfile *objfile : current_program_space->objfiles ())
+  for (objfile *objfile : pspace->objfiles ())
     {
       if (objfile->separate_debug_objfile_backlink != nullptr)
 	continue;
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index 0d9b9ad51cee..f84d3e818480 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -234,11 +234,11 @@ extern bound_minimal_symbol lookup_minimal_symbol_linkage (const char *name,
   ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2);
 
 /* A variant of lookup_minimal_symbol_linkage that iterates over all
-   objfiles.  If ONLY_MAIN is true, then only an objfile with
+   objfiles of PSPACE.  If ONLY_MAIN is true, then only an objfile with
    OBJF_MAINLINE will be considered.  */
 
-extern bound_minimal_symbol lookup_minimal_symbol_linkage (const char *name,
-							   bool only_main)
+extern bound_minimal_symbol lookup_minimal_symbol_linkage
+  (program_space *pspace, const char *name, bool only_main)
   ATTRIBUTE_NONNULL (1);
 
 /* Look through all the current minimal symbol tables and find the
diff --git a/gdb/symtab.c b/gdb/symtab.c
index c77537f121ae..9da148b3394d 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6775,10 +6775,12 @@ symbol::get_maybe_copied_address () const
   gdb_assert (this->aclass () == LOC_STATIC);
 
   const char *linkage_name = this->linkage_name ();
-  bound_minimal_symbol minsym = lookup_minimal_symbol_linkage (linkage_name,
-							       false);
+  bound_minimal_symbol minsym
+    = lookup_minimal_symbol_linkage (this->objfile ()->pspace (), linkage_name,
+				     false);
   if (minsym.minsym != nullptr)
     return minsym.value_address ();
+
   return this->m_value.address;
 }
 
@@ -6791,10 +6793,11 @@ minimal_symbol::get_maybe_copied_address (objfile *objf) const
   gdb_assert ((objf->flags & OBJF_MAINLINE) == 0);
 
   const char *linkage_name = this->linkage_name ();
-  bound_minimal_symbol found = lookup_minimal_symbol_linkage (linkage_name,
-							      true);
+  bound_minimal_symbol found
+    = lookup_minimal_symbol_linkage (objf->pspace (), linkage_name, true);
   if (found.minsym != nullptr)
     return found.value_address ();
+
   return (this->m_value.address
 	  + objf->section_offsets[this->section_index ()]);
 }
-- 
2.45.2



More information about the Gdb-patches mailing list