]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: pass core file to gdbarch_core_thread_name method
authorAndrew Burgess <aburgess@redhat.com>
Wed, 27 Aug 2025 19:14:03 +0000 (20:14 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Fri, 5 Sep 2025 09:37:04 +0000 (10:37 +0100)
Continuing the removal of 'current_program_space->core_bfd ()' from
GDB, this commit updates the gdbarch method 'gdbarch_core_thread_name'
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::thread_name.  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/fbsd-tdep.c
gdb/gdbarch-gen.c
gdb/gdbarch-gen.h
gdb/gdbarch_components.py

index abcf9f9848cd583b26d8b61136623fbd7b55ab71..b877a31edc6647c5b2ae0a5ca5037dc6c0f08474 100644 (file)
@@ -1800,7 +1800,11 @@ core_target::thread_name (struct thread_info *thr)
 {
   if (m_core_gdbarch != nullptr
       && gdbarch_core_thread_name_p (m_core_gdbarch))
-    return gdbarch_core_thread_name (m_core_gdbarch, thr);
+    {
+      bfd *cbfd = current_program_space->core_bfd ();
+      gdb_assert (cbfd != nullptr);
+      return gdbarch_core_thread_name (m_core_gdbarch, *cbfd, thr);
+    }
   return NULL;
 }
 
index 1dce4f88a97b00e435aa0c1be143b3dfc62415b4..32571b8eec753ba1a5c80fafa5ba29d4dd201707 100644 (file)
@@ -548,7 +548,8 @@ fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
    string in a static buffer.  */
 
 static const char *
-fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
+fbsd_core_thread_name (struct gdbarch *gdbarch, bfd &cbfd,
+                      struct thread_info *thr)
 {
   static char buf[80];
   struct bfd_section *section;
@@ -564,16 +565,15 @@ fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
         extract the null-terminated name from the start of the
         note.  */
       thread_section_name section_name (".thrmisc", thr->ptid);
-      bfd *cbfd = current_program_space->core_bfd ();
 
-      section = bfd_get_section_by_name (cbfd, section_name.c_str ());
+      section = bfd_get_section_by_name (&cbfd, section_name.c_str ());
       if (section != NULL && bfd_section_size (section) > 0)
        {
          /* Truncate the name if it is longer than "buf".  */
          size = bfd_section_size (section);
          if (size > sizeof buf - 1)
            size = sizeof buf - 1;
-         if (bfd_get_section_contents (cbfd, section, buf, (file_ptr) 0, size)
+         if (bfd_get_section_contents (&cbfd, section, buf, (file_ptr) 0, size)
              && buf[0] != '\0')
            {
              buf[size] = '\0';
@@ -582,7 +582,7 @@ fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
                 as its thread name instead of an empty name if a name
                 has not been set explicitly.  Return a NULL name in
                 that case.  */
-             if (strcmp (buf, elf_tdata (cbfd)->core->program) != 0)
+             if (strcmp (buf, elf_tdata (&cbfd)->core->program) != 0)
                return buf;
            }
        }
index 01f8e1b045cc23c8041c94519c13bf1e574a66e8..64a63037789e056748bce2471359f51451cfb840 100644 (file)
@@ -4042,13 +4042,13 @@ gdbarch_core_thread_name_p (struct gdbarch *gdbarch)
 }
 
 const char *
-gdbarch_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
+gdbarch_core_thread_name (struct gdbarch *gdbarch, struct bfd &cbfd, struct thread_info *thr)
 {
   gdb_assert (gdbarch != NULL);
   gdb_assert (gdbarch->core_thread_name != NULL);
   if (gdbarch_debug >= 2)
     gdb_printf (gdb_stdlog, "gdbarch_core_thread_name called\n");
-  return gdbarch->core_thread_name (gdbarch, thr);
+  return gdbarch->core_thread_name (gdbarch, cbfd, thr);
 }
 
 void
index 1de58512ec971748edc2c65af6f631f40b5fb619..c666802b85c3f6ba3b448dfd8ca8a5d09b772fb2 100644 (file)
@@ -1051,12 +1051,12 @@ typedef std::string (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, pt
 extern std::string gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
 extern void set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str);
 
-/* How the core target extracts the name of a thread from a core file. */
+/* How the core target extracts the name of a thread from core file CBFD. */
 
 extern bool gdbarch_core_thread_name_p (struct gdbarch *gdbarch);
 
-typedef const char * (gdbarch_core_thread_name_ftype) (struct gdbarch *gdbarch, struct thread_info *thr);
-extern const char * gdbarch_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr);
+typedef const char * (gdbarch_core_thread_name_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, struct thread_info *thr);
+extern const char * gdbarch_core_thread_name (struct gdbarch *gdbarch, struct bfd &cbfd, struct thread_info *thr);
 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
index 323f81ce4c05e089b78c8cf92c4a6d85d9cccce3..1f32087d03b1023afd59d8515c82ad61c4af2245 100644 (file)
@@ -1776,11 +1776,11 @@ How the core target converts a PTID from a core file to a string.
 
 Method(
     comment="""
-How the core target extracts the name of a thread from a core file.
+How the core target extracts the name of a thread from core file CBFD.
 """,
     type="const char *",
     name="core_thread_name",
-    params=[("struct thread_info *", "thr")],
+    params=[("struct bfd &", "cbfd"), ("struct thread_info *", "thr")],
     predicate=True,
 )