From patchwork Tue Oct 10 20:40:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 77458 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE85B38618E7 for ; Tue, 10 Oct 2023 20:46:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 9A18D3858C5E for ; Tue, 10 Oct 2023 20:46:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A18D3858C5E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (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 40E6D1E0D2; Tue, 10 Oct 2023 16:46:19 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 19/24] gdb: make so_list::abfd a gdb_bfd_ref_ptr Date: Tue, 10 Oct 2023 16:40:14 -0400 Message-ID: <20231010204213.111285-20-simon.marchi@efficios.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010204213.111285-1-simon.marchi@efficios.com> References: <20231010204213.111285-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3496.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org Change the field from a `bfd *` to a gdb_bfd_ref_ptr to automatically manage the reference. Change-Id: I3ace18bea985bc194c5e67bb559eec567e258950 --- gdb/solib-frv.c | 2 +- gdb/solib-rocm.c | 2 +- gdb/solib-target.c | 6 +++--- gdb/solib.c | 15 ++++++--------- gdb/solist.h | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index 5cbab1493128..2ed6280b5879 100644 --- a/gdb/solib-frv.c +++ b/gdb/solib-frv.c @@ -920,7 +920,7 @@ frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point) auto *li = gdb::checked_static_cast (so->lm_info.get ()); addr = find_canonical_descriptor_in_load_object - (entry_point, got_value, name, so->abfd, li); + (entry_point, got_value, name, so->abfd.get (), li); if (addr != 0) break; diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c index 3bd5dec6d052..9a9bfa36fddb 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -175,7 +175,7 @@ static void rocm_solib_relocate_section_addresses (so_list &so, struct target_section *sec) { - if (!is_amdgpu_arch (gdbarch_from_bfd (so.abfd))) + if (!is_amdgpu_arch (gdbarch_from_bfd (so.abfd.get ()))) { svr4_so_ops.relocate_section_addresses (so, sec); return; diff --git a/gdb/solib-target.c b/gdb/solib-target.c index 3743c77e9c76..cccdfa83c9c5 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -291,7 +291,7 @@ solib_target_relocate_section_addresses (so_list &so, target_section *sec) it any earlier, since we need to open the file first. */ if (li->offsets.empty ()) { - int num_sections = gdb_bfd_count_sections (so.abfd); + int num_sections = gdb_bfd_count_sections (so.abfd.get ()); li->offsets.assign (num_sections, 0); @@ -349,7 +349,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), else if (!li->segment_bases.empty ()) { symfile_segment_data_up data - = get_symfile_segment_data (so.abfd); + = get_symfile_segment_data (so.abfd.get ()); if (data == NULL) warning (_("\ @@ -359,7 +359,7 @@ Could not relocate shared library \"%s\": no segments"), so.so_name); ULONGEST orig_delta; int i; - if (!symfile_map_offsets_to_segments (so.abfd, data.get (), + if (!symfile_map_offsets_to_segments (so.abfd.get (), data.get (), li->offsets, li->segment_bases.size (), li->segment_bases.data ())) diff --git a/gdb/solib.c b/gdb/solib.c index fabb6e1d938b..6b7f0da0498d 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -580,7 +580,7 @@ solib_map_sections (so_list &so) return 0; /* Leave bfd open, core_xfer_memory and "info files" need it. */ - so.abfd = abfd.release (); + so.abfd = std::move (abfd); /* Copy the full path name into so_name, allowing symbol_file_add to find it later. This also affects the =library-loaded GDB/MI @@ -588,11 +588,11 @@ solib_map_sections (so_list &so) the library's host-side path. If we let the target dictate that objfile's path, and the target is different from the host, GDB/MI will not provide the correct host-side path. */ - if (strlen (bfd_get_filename (so.abfd)) >= SO_NAME_MAX_PATH_SIZE) + if (strlen (bfd_get_filename (so.abfd.get ())) >= SO_NAME_MAX_PATH_SIZE) error (_("Shared library file name is too long.")); - strcpy (so.so_name, bfd_get_filename (so.abfd)); + strcpy (so.so_name, bfd_get_filename (so.abfd.get ())); - so.sections = build_section_table (so.abfd); + so.sections = build_section_table (so.abfd.get ()); for (target_section &p : so.sections) { @@ -629,9 +629,7 @@ so_list::clear () const target_so_ops *ops = gdbarch_so_ops (current_inferior ()->arch ()); this->sections.clear (); - - gdb_bfd_unref (this->abfd); - this->abfd = NULL; + this->abfd = nullptr; /* Our caller closed the objfile, possibly via objfile_purge_solibs. */ this->symbols_loaded = 0; @@ -706,8 +704,7 @@ solib_read_symbols (so_list &so, symfile_add_flags flags) { section_addr_info sap = build_section_addr_info_from_section_table (so.sections); - gdb_bfd_ref_ptr tmp_bfd - (gdb_bfd_ref_ptr::new_reference (so.abfd)); + gdb_bfd_ref_ptr tmp_bfd = so.abfd; so.objfile = symbol_file_add_from_bfd (tmp_bfd, so.so_name, flags, &sap, OBJF_SHARED, NULL); diff --git a/gdb/solist.h b/gdb/solist.h index 51b985d53247..671f8812916c 100644 --- a/gdb/solist.h +++ b/gdb/solist.h @@ -76,7 +76,7 @@ struct so_list current_sos must initialize these fields to 0. */ - bfd *abfd = nullptr; + gdb_bfd_ref_ptr abfd; char symbols_loaded = 0; /* flag: symbols read in yet? */ /* objfile with symbols for a loaded library. Target memory is read from