]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: pass core file to gdbarch_core_xfer_siginfo
authorAndrew Burgess <aburgess@redhat.com>
Wed, 27 Aug 2025 10:49:24 +0000 (11:49 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 4 Sep 2025 15:43:19 +0000 (16:43 +0100)
Another patch that aims to remove 'current_program_space->core_bfd ()'
from GDB.  This time I'm passing the core file BFD as an argument to
the gdbarch method gdbarch_core_xfer_siginfo.

In corelow.c the core file is being passed, this does introduce a new
instance of 'current_program_space->core_bfd ()', but this is OK.  My
long term plan is to move the core bfd into core_target, in which case
the call to gdbarch_core_xfer_siginfo will have access to the core bfd
as a member variable.

For now though, this patch moves the accesses via global state up the
call stack, and consolidates the two calls from fbsd-tdep.c and
linux-tdep.c into the one call in corelow.c.

There should be no user visible changes after this commit.

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

index 02d13a81793861cc9b9662f95c9cd340eccab793..b91f49002746e14c60f401c34b90e8a767da2fa7 100644 (file)
@@ -1671,8 +1671,10 @@ core_target::xfer_partial (enum target_object object, const char *annex,
          if (m_core_gdbarch != nullptr
              && gdbarch_core_xfer_siginfo_p (m_core_gdbarch))
            {
-             LONGEST l = gdbarch_core_xfer_siginfo  (m_core_gdbarch, readbuf,
-                                                     offset, len);
+             struct bfd *cbfd = current_program_space->core_bfd ();
+             gdb_assert (cbfd != nullptr);
+             LONGEST l = gdbarch_core_xfer_siginfo  (m_core_gdbarch, *cbfd,
+                                                     readbuf, offset, len);
 
              if (l >= 0)
                {
index 171dbce86a0ed8aa7290dd971ff0d3d3e8eff0d7..a8f5e63eaaf0832ed687182b3f14efb76f3f1819 100644 (file)
@@ -594,8 +594,8 @@ fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
 /* Implement the "core_xfer_siginfo" gdbarch method.  */
 
 static LONGEST
-fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
-                       ULONGEST offset, ULONGEST len)
+fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, struct bfd &cbfd,
+                       gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
 {
   size_t siginfo_size;
 
@@ -607,13 +607,12 @@ fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
     return -1;
 
   thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid);
-  bfd *cbfd = current_program_space->core_bfd ();
-  asection *section = bfd_get_section_by_name (cbfd, section_name.c_str ());
+  asection *section = bfd_get_section_by_name (&cbfd, section_name.c_str ());
   if (section == NULL)
     return -1;
 
   gdb_byte buf[4];
-  if (!bfd_get_section_contents (cbfd, section, buf,
+  if (!bfd_get_section_contents (&cbfd, section, buf,
                                 LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4))
     return -1;
 
@@ -630,7 +629,7 @@ fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
   else
     siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO;
 
-  if (!bfd_get_section_contents (cbfd, section, readbuf,
+  if (!bfd_get_section_contents (&cbfd, section, readbuf,
                                 siginfo_offset + offset, len))
     return -1;
 
index 09bb4804c432917568d2dc38ccb2e44e18cdf0bb..025e5664be4c545f52b6b898b13bebb428582f2d 100644 (file)
@@ -4066,13 +4066,13 @@ gdbarch_core_xfer_siginfo_p (struct gdbarch *gdbarch)
 }
 
 LONGEST
-gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
+gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->core_xfer_siginfo != NULL);
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_core_xfer_siginfo called\n");
-  return gdbarch->core_xfer_siginfo (gdbarch, readbuf, offset, len);
+  return gdbarch->core_xfer_siginfo (gdbarch, cbfd, readbuf, offset, len);
 }
 
 void
index 7171c42fb63e7ee035091fc9961deb2a4f80407e..2870e7c9b93f8feac21e2082f17c13ca99c75483 100644 (file)
@@ -1060,13 +1060,13 @@ extern const char * gdbarch_core_thread_name (struct gdbarch *gdbarch, struct th
 extern void set_gdbarch_core_thread_name (struct gdbarch *gdbarch, gdbarch_core_thread_name_ftype *core_thread_name);
 
 /* Read offset OFFSET of TARGET_OBJECT_SIGNAL_INFO signal information
-   from core file into buffer READBUF with length LEN.  Return the number
+   from core file CBFD into buffer READBUF with length LEN.  Return the number
    of bytes read (zero indicates EOF, a negative value indicates failure). */
 
 extern bool gdbarch_core_xfer_siginfo_p (struct gdbarch *gdbarch);
 
-typedef LONGEST (gdbarch_core_xfer_siginfo_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
-extern LONGEST gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
+typedef LONGEST (gdbarch_core_xfer_siginfo_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
+extern LONGEST gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, struct bfd &cbfd, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
 extern void set_gdbarch_core_xfer_siginfo (struct gdbarch *gdbarch, gdbarch_core_xfer_siginfo_ftype *core_xfer_siginfo);
 
 /* Read x86 XSAVE layout information from core file into XSAVE_LAYOUT.
index f933a09c0fa64d05dca5bdebac0f889a87add0f2..5287451f060e4ca5d2d035688702ac1b62cbc26a 100644 (file)
@@ -1777,12 +1777,17 @@ How the core target extracts the name of a thread from a core file.
 Method(
     comment="""
 Read offset OFFSET of TARGET_OBJECT_SIGNAL_INFO signal information
-from core file into buffer READBUF with length LEN.  Return the number
+from core file CBFD into buffer READBUF with length LEN.  Return the number
 of bytes read (zero indicates EOF, a negative value indicates failure).
 """,
     type="LONGEST",
     name="core_xfer_siginfo",
-    params=[("gdb_byte *", "readbuf"), ("ULONGEST", "offset"), ("ULONGEST", "len")],
+    params=[
+        ("struct bfd &", "cbfd"),
+        ("gdb_byte *", "readbuf"),
+        ("ULONGEST", "offset"),
+        ("ULONGEST", "len")
+    ],
     predicate=True,
 )
 
index 4ec689c857250d19ba2aef4fc322b84b0a5be31b..f07f9879614c847ef49929388f1ad732521066af 100644 (file)
@@ -1307,18 +1307,15 @@ linux_core_info_proc (struct gdbarch *gdbarch, struct bfd *cbfd,
    interface.  */
 
 static LONGEST
-linux_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
-                        ULONGEST offset, ULONGEST len)
+linux_core_xfer_siginfo (struct gdbarch *gdbarch, struct bfd &cbfd,
+                        gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
 {
   thread_section_name section_name (".note.linuxcore.siginfo", inferior_ptid);
-  asection *section
-    = bfd_get_section_by_name (current_program_space->core_bfd (),
-                              section_name.c_str ());
-  if (section == NULL)
+  asection *section = bfd_get_section_by_name (&cbfd, section_name.c_str ());
+  if (section == nullptr)
     return -1;
 
-  if (!bfd_get_section_contents (current_program_space->core_bfd (), section,
-                                readbuf, offset, len))
+  if (!bfd_get_section_contents (&cbfd, section, readbuf, offset, len))
     return -1;
 
   return len;