[19/24] gdb: make so_list::abfd a gdb_bfd_ref_ptr

Message ID 20231010204213.111285-20-simon.marchi@efficios.com
State New
Headers
Series C++ification of struct so_list |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed

Commit Message

Simon Marchi Oct. 10, 2023, 8:40 p.m. UTC
  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(-)
  

Patch

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<lm_info_frv *> (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