[PATCH v3 3/6] gdb/solib: add solib -> solib_ops backlink

Simon Marchi simon.marchi@efficios.com
Mon Jun 16 19:33:01 GMT 2025


The subsequent C++ification commit makes it so that one struct solib_ops
is instantiated for each program space.  For some operations, it will
then become necessary to be able to get the right solib_ops instance
from a given solib.  Add an solib -> solib_ops backlink for that.

Change-Id: Ib95407b3fa5fcfba55cf874e0e9dcd2d43a402e4
---
 gdb/solib-aix.c    |  2 +-
 gdb/solib-darwin.c |  2 +-
 gdb/solib-dsbt.c   |  2 +-
 gdb/solib-frv.c    |  2 +-
 gdb/solib-rocm.c   |  2 +-
 gdb/solib-svr4.c   |  4 ++--
 gdb/solib-target.c |  2 +-
 gdb/solib.h        | 15 +++++++++++++++
 8 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index 4af83de4d371..17eeba940770 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -480,7 +480,7 @@ solib_aix_current_sos ()
 	}
 
       /* Add it to the list.  */
-      auto &new_solib = sos.emplace_back ();
+      auto &new_solib = sos.emplace_back (solib_aix_so_ops);
       new_solib.original_name = so_name;
       new_solib.name = so_name;
       new_solib.lm_info = std::make_unique<lm_info_aix> (info);
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 4003c77748ca..88a2962f5dd5 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -250,7 +250,7 @@ darwin_current_sos ()
 	break;
 
       /* Create and fill the new struct solib element.  */
-      auto &newobj = sos.emplace_back ();
+      auto &newobj = sos.emplace_back (darwin_so_ops);
 
       auto li = std::make_unique<lm_info_darwin> ();
 
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 2b3153692805..f6748b69353a 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -584,7 +584,7 @@ dsbt_current_sos (void)
 	      break;
 	    }
 
-	  auto &sop = sos.emplace_back ();
+	  auto &sop = sos.emplace_back (dsbt_so_ops);
 	  auto li = std::make_unique<lm_info_dsbt> ();
 	  li->map = loadmap;
 	  /* Fetch the name.  */
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index ceef72208a1b..12d3140b513c 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -367,7 +367,7 @@ frv_current_sos ()
 	      break;
 	    }
 
-	  auto &sop = sos.emplace_back ();
+	  auto &sop = sos.emplace_back (frv_so_ops);
 	  auto li = std::make_unique<lm_info_frv> ();
 	  li->map = loadmap;
 	  li->got_value = got_addr;
diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index b27613bbf91a..a3599562e795 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -210,7 +210,7 @@ solibs_from_rocm_sos (const std::vector<rocm_so> &sos)
 
   for (const rocm_so &so : sos)
     {
-      auto &newobj = dst.emplace_back ();
+      auto &newobj = dst.emplace_back (rocm_solib_ops);
 
       newobj.lm_info = std::make_unique<lm_info_svr4> (*so.lm_info);
       newobj.name = so.name;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 48aace1feb48..deefc2578599 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1050,7 +1050,7 @@ solib_from_svr4_sos (const std::vector<svr4_so> &sos)
 
   for (const svr4_so &so : sos)
     {
-      auto &newobj = dst.emplace_back ();
+      auto &newobj = dst.emplace_back (svr4_so_ops);
 
       newobj.name = so.name;
       newobj.original_name = so.name;
@@ -1250,7 +1250,7 @@ svr4_default_sos (svr4_info *info)
   li->l_addr_p = 1;
 
   owning_intrusive_list<solib> sos;
-  auto &newobj = sos.emplace_back ();
+  auto &newobj = sos.emplace_back (svr4_so_ops);
 
   newobj.lm_info = std::move (li);
   newobj.name = info->debug_loader_name;
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 68dc3cc92c0a..61b841928ff8 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -245,7 +245,7 @@ solib_target_current_sos (void)
   /* Build a struct solib for each entry on the list.  */
   for (lm_info_target_up &info : library_list)
     {
-      auto &new_solib = sos.emplace_back ();
+      auto &new_solib = sos.emplace_back (solib_target_so_ops);
 
       /* We don't need a copy of the name in INFO anymore.  */
       new_solib.name = std::move (info->name);
diff --git a/gdb/solib.h b/gdb/solib.h
index f5922aa5f5d6..09d56c08b953 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -54,8 +54,19 @@ struct lm_info
 
 using lm_info_up = std::unique_ptr<lm_info>;
 
+struct solib_ops;
+
 struct solib : intrusive_list_node<solib>
 {
+  /* Constructor
+
+     OPS is the solib_ops implementation providing this solib.  */
+  explicit solib (const solib_ops &ops) : m_ops (&ops) {}
+
+  /* Return the solib_ops implementation providing this solib.  */
+  const solib_ops &ops () const
+  { return *m_ops; }
+
   /* Free symbol-file related contents of SO and reset for possible reloading
      of SO.  If we have opened a BFD for SO, close it.  If we have placed SO's
      sections in some target's section table, the caller is responsible for
@@ -111,6 +122,10 @@ struct solib : intrusive_list_node<solib>
      that supports outputting multiple segments once the related code
      supports them.  */
   CORE_ADDR addr_low = 0, addr_high = 0;
+
+private:
+  /* The solib_ops responsible for this solib.  */
+  const solib_ops *m_ops;
 };
 
 /* A unique pointer to an solib.  */
-- 
2.49.0



More information about the Gdb-patches mailing list