From: Andrew Burgess Date: Wed, 27 Aug 2025 19:14:03 +0000 (+0100) Subject: gdb: pass core file to gdbarch_core_thread_name method X-Git-Tag: gdb-17-branchpoint~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6b9480111a0e90580f70bdd144105c0eabc8522;p=thirdparty%2Fbinutils-gdb.git gdb: pass core file to gdbarch_core_thread_name method 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 --- diff --git a/gdb/corelow.c b/gdb/corelow.c index abcf9f9848c..b877a31edc6 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -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; } diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 1dce4f88a97..32571b8eec7 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -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; } } diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c index 01f8e1b045c..64a63037789 100644 --- a/gdb/gdbarch-gen.c +++ b/gdb/gdbarch-gen.c @@ -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 diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 1de58512ec9..c666802b85c 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -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 diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 323f81ce4c0..1f32087d03b 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -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, )