From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QC7lEegVP2h/lj8AWB0awg (envelope-from ) for ; Tue, 03 Jun 2025 11:34:00 -0400 Received: by simark.ca (Postfix, from userid 112) id 30FB61E102; Tue, 3 Jun 2025 11:34:00 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=unavailable autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 55C6C1E0C2 for ; Tue, 3 Jun 2025 11:33:58 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD429385843D for ; Tue, 3 Jun 2025 15:33:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD429385843D Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id A6F713858408 for ; Tue, 3 Jun 2025 15:33:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6F713858408 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A6F713858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748964780; cv=none; b=I6X0lEuuTnySYTTcsatu0Z9C+z7JyTcpGuar9+EUORo1a0we3JaYOQBkZAuyhdOIZZpAPlVPXqpzNSQuklX92MvLLhnxqk3TRW2/+9m4n55DOM2KRtPDWKM4sTFJ4ZQQSfHgRtdUVrR1CjJJ4DHCpJgDKYwpB1s0AVax87SDa1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748964780; c=relaxed/simple; bh=IB1+hUiWrga5d6e4igzhh65wQdrpgpL+ng2a9XN4i/U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wu4j/+8PpP0G8JeJlWR9IHL7xDkpq3Q/Qt/I98nDRGIqqzUBOIcA4VGZJO39aCTRYwRDn+QJby4u9PNWvCnQcJwLDkHPn6ZfX2IM242MlD8tL2KI3gYPFiluoEofQnNdHq9FwSm0T5Nmc553qCvGZY7Rcn/mj8+VJdUmI2eZPV8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6F713858408 Received: by simark.ca (Postfix, from userid 112) id 2FB311E11C; Tue, 3 Jun 2025 11:33:00 -0400 (EDT) Received: from smarchi-efficios.internal.efficios.com (192-222-132-26.qc.cable.ebox.net [192.222.132.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 7191F1E0C2; Tue, 3 Jun 2025 11:32:58 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb/solib: pass lm_info, original_name and name to solib constructor Date: Tue, 3 Jun 2025 11:32:54 -0400 Message-ID: <20250603153257.55235-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 --- gdb/solib-aix.c | 5 +---- gdb/solib-darwin.c | 17 +++++++---------- gdb/solib-dsbt.c | 21 +++++++++++---------- gdb/solib-frv.c | 33 ++++++++++++++++----------------- gdb/solib-rocm.c | 9 ++------- gdb/solib-svr4.c | 16 ++++------------ gdb/solib-target.c | 9 +-------- gdb/solib.h | 6 ++++++ 8 files changed, 48 insertions(+), 68 deletions(-) diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c index 4af83de4d371..733c74dc9c3b 100644 --- a/gdb/solib-aix.c +++ b/gdb/solib-aix.c @@ -480,10 +480,7 @@ solib_aix_current_sos () } /* Add it to the list. */ - auto &new_solib = sos.emplace_back (); - 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); } return sos; diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c index 4003c77748ca..81047c38a9d4 100644 --- a/gdb/solib-darwin.c +++ b/gdb/solib-darwin.c @@ -137,8 +137,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. */ @@ -250,15 +254,8 @@ darwin_current_sos () break; /* Create and fill the new struct solib element. */ - auto &newobj = sos.emplace_back (); - - 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 ()); } return sos; diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c index 2b3153692805..1f03e2b1edb1 100644 --- a/gdb/solib-dsbt.c +++ b/gdb/solib-dsbt.c @@ -124,13 +124,19 @@ struct dbst_ext_link_map 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. */ @@ -584,9 +590,6 @@ dsbt_current_sos (void) break; } - auto &sop = sos.emplace_back (); - auto li = std::make_unique (); - li->map = loadmap; /* Fetch the name. */ addr = extract_unsigned_integer (lm_buf.l_name, sizeof (lm_buf.l_name), @@ -601,12 +604,11 @@ dsbt_current_sos (void) 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 () : ""); } else { @@ -789,8 +791,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 ceef72208a1b..2af4dd9f10ab 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -197,6 +197,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); @@ -205,11 +212,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(). @@ -367,13 +374,6 @@ frv_current_sos () break; } - auto &sop = sos.emplace_back (); - 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), @@ -385,11 +385,11 @@ frv_current_sos () 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 () : ""); } else { @@ -725,8 +725,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 92fb91563f00..ef01720ecf4b 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -209,13 +209,8 @@ solibs_from_rocm_sos (const std::vector &sos) owning_intrusive_list dst; for (const rocm_so &so : sos) - { - auto &newobj = dst.emplace_back (); - - 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); return dst; } diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 5a8b08edacda..44cad5ed2782 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1053,13 +1053,8 @@ solib_from_svr4_sos (const std::vector &sos) owning_intrusive_list dst; for (const svr4_so &so : sos) - { - auto &newobj = dst.emplace_back (); - - 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); return dst; } @@ -1254,11 +1249,8 @@ svr4_default_sos (svr4_info *info) li->l_addr_p = 1; owning_intrusive_list sos; - auto &newobj = sos.emplace_back (); - - 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); return sos; } diff --git a/gdb/solib-target.c b/gdb/solib-target.c index 68dc3cc92c0a..dce90a5f8c8e 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -244,14 +244,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 (); - - /* We don't need a copy of the name in INFO anymore. */ - new_solib.name = std::move (info->name); - new_solib.original_name = new_solib.name; - new_solib.lm_info = std::move (info); - } + sos.emplace_back (std::move (info), info->name, info->name); return sos; } diff --git a/gdb/solib.h b/gdb/solib.h index f5922aa5f5d6..2bcfb63a82a4 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -56,6 +56,12 @@ using lm_info_up = std::unique_ptr; struct solib : intrusive_list_node { + solib (lm_info_up lm_info, std::string original_name, std::string name) + : lm_info (std::move (lm_info)), + original_name (std::move (original_name)), + name (std::move (name)) + {} + /* 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 base-commit: 0b5023cc71d3af8b18e10e6599a3f9381bc15265 -- 2.49.0