]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/solib: pass lm_info, original_name and name to solib constructor
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 9 Jul 2025 14:12:17 +0000 (10:12 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 18 Sep 2025 19:52:19 +0000 (15:52 -0400)
These values are always known at construction time, so pass them to the
constructor.

Add constructors to some lm_info_* types when it's easy and it makes
things cleaner.

Change-Id: Ie2d751be276470c10c81792a93bf3ddafbcd4c33
Approved-By: Tom Tromey <tom@tromey.com>
gdb/solib-aix.c
gdb/solib-darwin.c
gdb/solib-dsbt.c
gdb/solib-frv.c
gdb/solib-rocm.c
gdb/solib-svr4.c
gdb/solib-target.c
gdb/solib.h

index 6859092a78360643e2e3c28e33a1737d3bc12a46..308ff80c38caf8ad3a95fcc844b8bb158eed0a48 100644 (file)
@@ -495,10 +495,8 @@ aix_solib_ops::current_sos () const
        }
 
       /* Add it to the list.  */
-      auto &new_solib = sos.emplace_back (*this);
-      new_solib.original_name = so_name;
-      new_solib.name = so_name;
-      new_solib.lm_info = std::make_unique<lm_info_aix> (info);
+      sos.emplace_back (std::make_unique<lm_info_aix> (info), so_name, so_name,
+                       *this);
     }
 
   return sos;
index 62126974e012be9f5f1da352e45a72fde7bc756a..a6f550464f10aa75869711cb113532585c59b2a3 100644 (file)
@@ -158,8 +158,12 @@ darwin_load_image_infos (struct darwin_info *info)
 
 struct lm_info_darwin final : public lm_info
 {
+  explicit lm_info_darwin (CORE_ADDR lm_addr)
+    : lm_addr (lm_addr)
+  {}
+
   /* The target location of lm.  */
-  CORE_ADDR lm_addr = 0;
+  CORE_ADDR lm_addr;
 };
 
 /* Lookup the value for a specific symbol.  */
@@ -269,15 +273,8 @@ darwin_solib_ops::current_sos () const
        break;
 
       /* Create and fill the new struct solib element.  */
-      auto &newobj = sos.emplace_back (*this);
-
-      auto li = std::make_unique<lm_info_darwin> ();
-
-      newobj.name = file_path.get ();
-      newobj.original_name = newobj.name;
-      li->lm_addr = load_addr;
-
-      newobj.lm_info = std::move (li);
+      sos.emplace_back (std::make_unique<lm_info_darwin> (load_addr),
+                       file_path.get (), file_path.get (), *this);
     }
 
   return sos;
index 6b5b646480e609985289b45ca0a8de2a8c11d345..719678b56aad3a1c54fed65d45351a6e1d9b0871 100644 (file)
@@ -144,13 +144,19 @@ make_dsbt_solib_ops (program_space *pspace)
 
 struct lm_info_dsbt final : public lm_info
 {
+  explicit lm_info_dsbt (int_elf32_dsbt_loadmap *map)
+    : map (map)
+  {}
+
+  DISABLE_COPY_AND_ASSIGN (lm_info_dsbt);
+
   ~lm_info_dsbt ()
   {
     xfree (this->map);
   }
 
   /* The loadmap, digested into an easier to use form.  */
-  int_elf32_dsbt_loadmap *map = NULL;
+  int_elf32_dsbt_loadmap *map;
 };
 
 /* Per pspace dsbt specific data.  */
@@ -604,9 +610,6 @@ dsbt_solib_ops::current_sos () const
              break;
            }
 
-         auto &sop = sos.emplace_back (*this);
-         auto li = std::make_unique<lm_info_dsbt> ();
-         li->map = loadmap;
          /* Fetch the name.  */
          addr = extract_unsigned_integer (lm_buf.l_name,
                                           sizeof (lm_buf.l_name),
@@ -621,12 +624,12 @@ dsbt_solib_ops::current_sos () const
              if (solib_dsbt_debug)
                gdb_printf (gdb_stdlog, "current_sos: name = %s\n",
                            name_buf.get ());
-
-             sop.name = name_buf.get ();
-             sop.original_name = sop.name;
            }
 
-         sop.lm_info = std::move (li);
+         sos.emplace_back (std::make_unique<lm_info_dsbt> (loadmap),
+                           name_buf != nullptr ? name_buf.get () : "",
+                           name_buf != nullptr ? name_buf.get () : "",
+                           *this);
        }
       else
        {
@@ -809,8 +812,7 @@ dsbt_relocate_main_executable (void)
   ldm = info->exec_loadmap;
 
   delete info->main_executable_lm_info;
-  info->main_executable_lm_info = new lm_info_dsbt;
-  info->main_executable_lm_info->map = ldm;
+  info->main_executable_lm_info = new lm_info_dsbt (ldm);
 
   objfile *objf = current_program_space->symfile_object_file;
   section_offsets new_offsets (objf->section_offsets.size ());
index e6499f46937829d94079ffb0f94768601ccddac2..ac5872e2938fd0f7c1d0f78c4226a1eb7f3e72be 100644 (file)
@@ -218,6 +218,13 @@ struct ext_link_map
 
 struct lm_info_frv final : public lm_info
 {
+  lm_info_frv (int_elf32_fdpic_loadmap *map, CORE_ADDR got_value,
+              CORE_ADDR lm_addr)
+    : map (map), got_value (got_value), lm_addr (lm_addr)
+  {}
+
+  DISABLE_COPY_AND_ASSIGN (lm_info_frv);
+
   ~lm_info_frv ()
   {
     xfree (this->map);
@@ -226,11 +233,11 @@ struct lm_info_frv final : public lm_info
   }
 
   /* The loadmap, digested into an easier to use form.  */
-  int_elf32_fdpic_loadmap *map = NULL;
+  int_elf32_fdpic_loadmap *map;
   /* The GOT address for this link map entry.  */
-  CORE_ADDR got_value = 0;
+  CORE_ADDR got_value;
   /* The link map address, needed for frv_fetch_objfile_link_map().  */
-  CORE_ADDR lm_addr = 0;
+  CORE_ADDR lm_addr;
 
   /* Cached dynamic symbol table and dynamic relocs initialized and
      used only by find_canonical_descriptor_in_load_object().
@@ -385,13 +392,6 @@ frv_solib_ops::current_sos () const
              break;
            }
 
-         auto &sop = sos.emplace_back (*this);
-         auto li = std::make_unique<lm_info_frv> ();
-         li->map = loadmap;
-         li->got_value = got_addr;
-         li->lm_addr = lm_addr;
-         sop.lm_info = std::move (li);
-
          /* Fetch the name.  */
          addr = extract_unsigned_integer (lm_buf.l_name,
                                           sizeof (lm_buf.l_name),
@@ -403,11 +403,12 @@ frv_solib_ops::current_sos () const
 
          if (name_buf == nullptr)
            warning (_("Can't read pathname for link map entry."));
-         else
-           {
-             sop.name = name_buf.get ();
-             sop.original_name = sop.name;
-           }
+
+         sos.emplace_back (std::make_unique<lm_info_frv> (loadmap, got_addr,
+                                                          lm_addr),
+                           name_buf != nullptr ? name_buf.get () : "",
+                           name_buf != nullptr ? name_buf.get () : "",
+                           *this);
        }
       else
        {
@@ -743,8 +744,7 @@ frv_relocate_main_executable (void)
     error (_("Unable to load the executable's loadmap."));
 
   delete main_executable_lm_info;
-  main_executable_lm_info = new lm_info_frv;
-  main_executable_lm_info->map = ldm;
+  main_executable_lm_info = new lm_info_frv (ldm, 0, 0);
 
   objfile *objf = current_program_space->symfile_object_file;
   section_offsets new_offsets (objf->section_offsets.size ());
index c3c2e44505e0b8b8b92fab0c32e85724a59647f4..3b121e67cc2b99d31525c80e0c4906295da87e48 100644 (file)
@@ -280,13 +280,8 @@ rocm_solib_ops::solibs_from_rocm_sos (const std::vector<rocm_so> &sos) const
   owning_intrusive_list<solib> dst;
 
   for (const rocm_so &so : sos)
-    {
-      auto &newobj = dst.emplace_back (*this);
-
-      newobj.lm_info = std::make_unique<lm_info_svr4> (*so.lm_info);
-      newobj.name = so.name;
-      newobj.original_name = so.unique_name;
-    }
+    dst.emplace_back (std::make_unique<lm_info_svr4> (*so.lm_info),
+                     so.unique_name, so.name, *this);
 
   return dst;
 }
index 58432b69a5d5c7e6f566c81c308caf7b07ac570c..27e034306d59634fc02b02bb94c0ec179755f4a2 100644 (file)
@@ -1069,13 +1069,8 @@ svr4_solib_ops::solibs_from_svr4_sos (const std::vector<svr4_so> &sos) const
   owning_intrusive_list<solib> dst;
 
   for (const svr4_so &so : sos)
-    {
-      auto &newobj = dst.emplace_back (*this);
-
-      newobj.name = so.name;
-      newobj.original_name = so.name;
-      newobj.lm_info = std::make_unique<lm_info_svr4> (*so.lm_info);
-    }
+    dst.emplace_back (std::make_unique<lm_info_svr4> (*so.lm_info), so.name,
+                     so.name, *this);
 
   return dst;
 }
@@ -1275,11 +1270,8 @@ svr4_solib_ops::default_sos (svr4_info *info) const
   li->l_addr_p = 1;
 
   owning_intrusive_list<solib> sos;
-  auto &newobj = sos.emplace_back (*this);
-
-  newobj.lm_info = std::move (li);
-  newobj.name = info->debug_loader_name;
-  newobj.original_name = newobj.name;
+  sos.emplace_back (std::move (li), info->debug_loader_name,
+                   info->debug_loader_name, *this);
 
   return sos;
 }
index f7e465f07ddbaddfd10e286ad18a6ee5e500a971..2ae25a8f3aea06a94d4f6c767456303d3a3b0f4f 100644 (file)
@@ -249,14 +249,8 @@ target_solib_ops::current_sos () const
 
   /* Build a struct solib for each entry on the list.  */
   for (auto &library : library_list)
-    {
-      auto &new_solib = sos.emplace_back (*this);
-
-      /* We don't need a copy of the name in INFO anymore.  */
-      new_solib.name = std::move (library.name);
-      new_solib.original_name = new_solib.name;
-      new_solib.lm_info = std::move (library.info);
-    }
+    sos.emplace_back (std::move (library.info), library.name, library.name,
+                     *this);
 
   return sos;
 }
index eb8bafef0bd2403cf3ecffd8e329488dc36ebe1c..85ea6675b7998d7a80ae9b695d36c22097e01e76 100644 (file)
@@ -61,7 +61,13 @@ 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) {}
+  explicit solib (lm_info_up lm_info, std::string original_name,
+                 std::string name, const solib_ops &ops)
+    : lm_info (std::move (lm_info)),
+      original_name (std::move (original_name)),
+      name (std::move (name)),
+      m_ops (&ops)
+  {}
 
   /* Return the solib_ops implementation providing this solib.  */
   const solib_ops &ops () const