]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: pass core file through gdbarch API when loading shared libraries
authorAndrew Burgess <aburgess@redhat.com>
Wed, 27 Aug 2025 19:11:06 +0000 (20:11 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 5 Sep 2025 09:36:24 +0000 (10:36 +0100)
Continuing the removal of 'current_program_space->core_bfd ()' from
GDB, this commit updates two gdbarch methods:

  gdbarch_core_xfer_shared_libraries
  gdbarch_core_xfer_shared_libraries_aix

to take the core file BFD as a reference parameter.  For now this just
moves the 'current_program_space->core_bfd ()' calls up the program
stack into core_target::xfer_partial.  In the future I plan to move
the core file BFD object out of the program_space and into the
core_target, at which point these new global accesses can also be
removed.

There should be no user visible changes after this commit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/corelow.c
gdb/gdbarch-gen.c
gdb/gdbarch-gen.h
gdb/gdbarch_components.py
gdb/rs6000-aix-tdep.c
gdb/windows-tdep.c
gdb/windows-tdep.h

index b91f49002746e14c60f401c34b90e8a767da2fa7..abcf9f9848cd583b26d8b61136623fbd7b55ab71 100644 (file)
@@ -1632,9 +1632,9 @@ core_target::xfer_partial (enum target_object object, const char *annex,
            return TARGET_XFER_E_IO;
          else
            {
-             *xfered_len = gdbarch_core_xfer_shared_libraries (m_core_gdbarch,
-                                                               readbuf,
-                                                               offset, len);
+             *xfered_len = gdbarch_core_xfer_shared_libraries
+               (m_core_gdbarch, *current_program_space->core_bfd (),
+                readbuf, offset, len);
 
              if (*xfered_len == 0)
                return TARGET_XFER_EOF;
@@ -1653,9 +1653,9 @@ core_target::xfer_partial (enum target_object object, const char *annex,
          else
            {
              *xfered_len
-               = gdbarch_core_xfer_shared_libraries_aix (m_core_gdbarch,
-                                                         readbuf, offset,
-                                                         len);
+               = gdbarch_core_xfer_shared_libraries_aix
+               (m_core_gdbarch, *current_program_space->core_bfd (),
+                readbuf, offset, len);
 
              if (*xfered_len == 0)
                return TARGET_XFER_EOF;
index 025e5664be4c545f52b6b898b13bebb428582f2d..01f8e1b045cc23c8041c94519c13bf1e574a66e8 100644 (file)
@@ -3970,13 +3970,13 @@ gdbarch_core_xfer_shared_libraries_p (struct gdbarch *gdbarch)
 }
 
 ULONGEST
-gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
+gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->core_xfer_shared_libraries != NULL);
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_core_xfer_shared_libraries called\n");
-  return gdbarch->core_xfer_shared_libraries (gdbarch, readbuf, offset, len);
+  return gdbarch->core_xfer_shared_libraries (gdbarch, cbfd, readbuf, offset, len);
 }
 
 void
@@ -3994,13 +3994,13 @@ gdbarch_core_xfer_shared_libraries_aix_p (struct gdbarch *gdbarch)
 }
 
 ULONGEST
-gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
+gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->core_xfer_shared_libraries_aix != NULL);
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_core_xfer_shared_libraries_aix called\n");
-  return gdbarch->core_xfer_shared_libraries_aix (gdbarch, readbuf, offset, len);
+  return gdbarch->core_xfer_shared_libraries_aix (gdbarch, cbfd, readbuf, offset, len);
 }
 
 void
index 2870e7c9b93f8feac21e2082f17c13ca99c75483..1de58512ec971748edc2c65af6f631f40b5fb619 100644 (file)
@@ -1029,8 +1029,8 @@ extern void set_gdbarch_decode_memtag_section (struct gdbarch *gdbarch, gdbarch_
 
 extern bool gdbarch_core_xfer_shared_libraries_p (struct gdbarch *gdbarch);
 
-typedef ULONGEST (gdbarch_core_xfer_shared_libraries_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
-extern ULONGEST gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
+typedef ULONGEST (gdbarch_core_xfer_shared_libraries_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
+extern ULONGEST gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
 extern void set_gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdbarch_core_xfer_shared_libraries_ftype *core_xfer_shared_libraries);
 
 /* Read offset OFFSET of TARGET_OBJECT_LIBRARIES_AIX formatted shared
@@ -1039,8 +1039,8 @@ extern void set_gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb
 
 extern bool gdbarch_core_xfer_shared_libraries_aix_p (struct gdbarch *gdbarch);
 
-typedef ULONGEST (gdbarch_core_xfer_shared_libraries_aix_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
-extern ULONGEST gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
+typedef ULONGEST (gdbarch_core_xfer_shared_libraries_aix_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
+extern ULONGEST gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
 extern void set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdbarch_core_xfer_shared_libraries_aix_ftype *core_xfer_shared_libraries_aix);
 
 /* How the core target converts a PTID from a core file to a string. */
index 20f9c8059f3eb508f0e3e5e857d3ea4e439780a2..323f81ce4c05e089b78c8cf92c4a6d85d9cccce3 100644 (file)
@@ -1738,7 +1738,12 @@ failed, otherwise, return the red length of READBUF.
 """,
     type="ULONGEST",
     name="core_xfer_shared_libraries",
-    params=[("gdb_byte *", "readbuf"), ("ULONGEST", "offset"), ("ULONGEST", "len")],
+    params=[
+        ("struct bfd &", "cbfd"),
+        ("gdb_byte *", "readbuf"),
+        ("ULONGEST", "offset"),
+        ("ULONGEST", "len"),
+    ],
     predicate=True,
 )
 
@@ -1750,7 +1755,12 @@ Return the number of bytes read (zero indicates failure).
 """,
     type="ULONGEST",
     name="core_xfer_shared_libraries_aix",
-    params=[("gdb_byte *", "readbuf"), ("ULONGEST", "offset"), ("ULONGEST", "len")],
+    params=[
+        ("struct bfd &", "cbfd"),
+        ("gdb_byte *", "readbuf"),
+        ("ULONGEST", "offset"),
+        ("ULONGEST", "len"),
+    ],
     predicate=True,
 )
 
index 6322bbc62cfd4ed586fc2bf2ecd08e49dc760de7..536f6473f88fedfcf3e37be6c7e15cc2e2b094ad 100644 (file)
@@ -1330,6 +1330,7 @@ rs6000_aix_ld_info_to_xml (struct gdbarch *gdbarch, const gdb_byte *ldi_buf,
 
 static ULONGEST
 rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
+                                          struct bfd &cbfd,
                                           gdb_byte *readbuf,
                                           ULONGEST offset,
                                           ULONGEST len)
@@ -1337,8 +1338,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
   struct bfd_section *ldinfo_sec;
   int ldinfo_size;
 
-  ldinfo_sec = bfd_get_section_by_name (current_program_space->core_bfd (),
-                                       ".ldinfo");
+  ldinfo_sec = bfd_get_section_by_name (&cbfd, ".ldinfo");
   if (ldinfo_sec == NULL)
     error (_("cannot find .ldinfo section from core file: %s"),
           bfd_errmsg (bfd_get_error ()));
@@ -1346,8 +1346,7 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 
   gdb::byte_vector ldinfo_buf (ldinfo_size);
 
-  if (! bfd_get_section_contents (current_program_space->core_bfd (),
-                                 ldinfo_sec, ldinfo_buf.data (), 0,
+  if (! bfd_get_section_contents (&cbfd, ldinfo_sec, ldinfo_buf.data (), 0,
                                  ldinfo_size))
     error (_("unable to read .ldinfo section from core file: %s"),
          bfd_errmsg (bfd_get_error ()));
index 9157ebe03b36bbdfdbd65ac0019fe5f53d7d8ea6..c6f5803f37a224d8d2f2cdb425b33652fcfac25e 100644 (file)
@@ -1162,13 +1162,11 @@ core_process_module_section (bfd *abfd, asection *sect, void *obj)
 
 ULONGEST
 windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
-                                   gdb_byte *readbuf,
+                                   struct bfd &cbfd, gdb_byte *readbuf,
                                    ULONGEST offset, ULONGEST len)
 {
   cpms_data data { gdbarch, "<library-list>\n", 0 };
-  bfd_map_over_sections (current_program_space->core_bfd (),
-                        core_process_module_section,
-                        &data);
+  bfd_map_over_sections (&cbfd, core_process_module_section, &data);
   data.xml += "</library-list>\n";
 
   ULONGEST len_avail = data.xml.length ();
index 87a618edfd09766f72d86a18666766a332e25aac..4d8e6bc822653e8cc7434d2bda132d6b744ccf1a 100644 (file)
@@ -33,6 +33,7 @@ extern void windows_xfer_shared_library (const char* so_name,
                                         std::string &xml);
 
 extern ULONGEST windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
+                                                   struct bfd &cbfd,
                                                    gdb_byte *readbuf,
                                                    ULONGEST offset,
                                                    ULONGEST len);