From 200b85632a99e749e14d1c026b7e24c15a5e2776 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 10 Oct 2023 16:01:08 +0000 Subject: [PATCH] gdb: make so_list::abfd a gdb_bfd_ref_ptr Change the field from a `bfd *` to a gdb_bfd_ref_ptr to automatically manage the reference. Change-Id: I3ace18bea985bc194c5e67bb559eec567e258950 Approved-By: Pedro Alves Reviewed-By: Reviewed-By: Lancelot Six --- gdb/solib-frv.c | 2 +- gdb/solib-rocm.c | 2 +- gdb/solib-target.c | 6 +++--- gdb/solib.c | 13 +++++-------- gdb/solist.h | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c index 5cbab149312..2ed6280b587 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 8162374d1ad..30e3bea0464 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 3743c77e9c7..cccdfa83c9c 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 db21a5122ed..e0437bb4b28 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,8 +629,6 @@ so_list::clear () const target_so_ops *ops = gdbarch_so_ops (current_inferior ()->arch ()); this->sections.clear (); - - gdb_bfd_unref (this->abfd); this->abfd = nullptr; /* Our caller closed the objfile, possibly via objfile_purge_solibs. */ @@ -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 51b985d5324..671f8812916 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 -- 2.30.2