From: Simon Marchi Date: Wed, 9 Jul 2025 14:12:17 +0000 (-0400) Subject: gdb/solib: pass lm_info, original_name and name to solib constructor X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=01f3393a178917afd73fb0a1fee41408a43d7047;p=thirdparty%2Fbinutils-gdb.git gdb/solib: pass lm_info, original_name and name to solib constructor 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 --- diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c index 6859092a783..308ff80c38c 100644 --- a/gdb/solib-aix.c +++ b/gdb/solib-aix.c @@ -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 (info); + sos.emplace_back (std::make_unique (info), so_name, so_name, + *this); } return sos; diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c index 62126974e01..a6f550464f1 100644 --- a/gdb/solib-darwin.c +++ b/gdb/solib-darwin.c @@ -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 (); - - 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 (load_addr), + file_path.get (), file_path.get (), *this); } return sos; diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 6b5b646480e..719678b56aa 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -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 (); - 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 (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 ()); diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index e6499f46937..ac5872e2938 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -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 (); - 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 (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 ()); diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c index c3c2e44505e..3b121e67cc2 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -280,13 +280,8 @@ rocm_solib_ops::solibs_from_rocm_sos (const std::vector &sos) const owning_intrusive_list dst; for (const rocm_so &so : sos) - { - auto &newobj = dst.emplace_back (*this); - - newobj.lm_info = std::make_unique (*so.lm_info); - newobj.name = so.name; - newobj.original_name = so.unique_name; - } + dst.emplace_back (std::make_unique (*so.lm_info), + so.unique_name, so.name, *this); return dst; } diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 58432b69a5d..27e034306d5 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1069,13 +1069,8 @@ svr4_solib_ops::solibs_from_svr4_sos (const std::vector &sos) const owning_intrusive_list 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 (*so.lm_info); - } + dst.emplace_back (std::make_unique (*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 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; } diff --git a/gdb/solib-target.c b/gdb/solib-target.c index f7e465f07dd..2ae25a8f3ae 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -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; } diff --git a/gdb/solib.h b/gdb/solib.h index eb8bafef0bd..85ea6675b79 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -61,7 +61,13 @@ struct solib : intrusive_list_node /* 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