From: Andrew Burgess Date: Wed, 27 Aug 2025 19:24:02 +0000 (+0100) Subject: gdb: pass core file to gdbarch_core_read_x86_xsave_layout X-Git-Tag: gdb-17-branchpoint~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6138daaf5f6e2a4680d53fbaf156548b1c25548;p=thirdparty%2Fbinutils-gdb.git gdb: pass core file to gdbarch_core_read_x86_xsave_layout Continuing the removal of 'current_program_space->core_bfd ()' from GDB, this commit updates the gdbarch method 'gdbarch_core_read_x86_xsave_layout' 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::fetch_x86_xsave_layout. 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 b877a31edc6..29eafe8bdfd 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1912,7 +1912,9 @@ core_target::fetch_x86_xsave_layout () gdbarch_core_read_x86_xsave_layout_p (m_core_gdbarch)) { x86_xsave_layout layout; - if (!gdbarch_core_read_x86_xsave_layout (m_core_gdbarch, layout)) + bfd *cbfd = current_program_space->core_bfd (); + gdb_assert (cbfd != nullptr); + if (!gdbarch_core_read_x86_xsave_layout (m_core_gdbarch, *cbfd, layout)) return {}; return layout; diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c index 64a63037789..7887b1386c6 100644 --- a/gdb/gdbarch-gen.c +++ b/gdb/gdbarch-gen.c @@ -4090,13 +4090,13 @@ gdbarch_core_read_x86_xsave_layout_p (struct gdbarch *gdbarch) } bool -gdbarch_core_read_x86_xsave_layout (struct gdbarch *gdbarch, x86_xsave_layout &xsave_layout) +gdbarch_core_read_x86_xsave_layout (struct gdbarch *gdbarch, struct bfd &cbfd, x86_xsave_layout &xsave_layout) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->core_read_x86_xsave_layout != NULL); if (gdbarch_debug >= 2) gdb_printf (gdb_stdlog, "gdbarch_core_read_x86_xsave_layout called\n"); - return gdbarch->core_read_x86_xsave_layout (gdbarch, xsave_layout); + return gdbarch->core_read_x86_xsave_layout (gdbarch, cbfd, xsave_layout); } void diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index c666802b85c..24fa8bab2db 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -1069,13 +1069,13 @@ typedef LONGEST (gdbarch_core_xfer_siginfo_ftype) (struct gdbarch *gdbarch, stru 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. +/* Read x86 XSAVE layout information from core file CBFD into XSAVE_LAYOUT. Returns true if the layout was read successfully. */ extern bool gdbarch_core_read_x86_xsave_layout_p (struct gdbarch *gdbarch); -typedef bool (gdbarch_core_read_x86_xsave_layout_ftype) (struct gdbarch *gdbarch, x86_xsave_layout &xsave_layout); -extern bool gdbarch_core_read_x86_xsave_layout (struct gdbarch *gdbarch, x86_xsave_layout &xsave_layout); +typedef bool (gdbarch_core_read_x86_xsave_layout_ftype) (struct gdbarch *gdbarch, struct bfd &cbfd, x86_xsave_layout &xsave_layout); +extern bool gdbarch_core_read_x86_xsave_layout (struct gdbarch *gdbarch, struct bfd &cbfd, x86_xsave_layout &xsave_layout); extern void set_gdbarch_core_read_x86_xsave_layout (struct gdbarch *gdbarch, gdbarch_core_read_x86_xsave_layout_ftype *core_read_x86_xsave_layout); /* BFD target to use when generating a core file. */ diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 1f32087d03b..3820ae3c94c 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -1803,12 +1803,12 @@ of bytes read (zero indicates EOF, a negative value indicates failure). Method( comment=""" -Read x86 XSAVE layout information from core file into XSAVE_LAYOUT. +Read x86 XSAVE layout information from core file CBFD into XSAVE_LAYOUT. Returns true if the layout was read successfully. """, type="bool", name="core_read_x86_xsave_layout", - params=[("x86_xsave_layout &", "xsave_layout")], + params=[("struct bfd &", "cbfd"), ("x86_xsave_layout &", "xsave_layout")], predicate=True, ) diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c index 827d53ce5d0..a32880e0be3 100644 --- a/gdb/i386-fbsd-tdep.c +++ b/gdb/i386-fbsd-tdep.c @@ -274,11 +274,10 @@ i386_fbsd_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout) /* See i386-fbsd-tdep.h. */ bool -i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch, +i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch, bfd &cbfd, x86_xsave_layout &layout) { - return i386_fbsd_core_read_xsave_info (current_program_space->core_bfd (), - layout) != 0; + return i386_fbsd_core_read_xsave_info (&cbfd, layout) != 0; } /* Implement the core_read_description gdbarch method. */ diff --git a/gdb/i386-fbsd-tdep.h b/gdb/i386-fbsd-tdep.h index 70ad32fecdd..acc57765827 100644 --- a/gdb/i386-fbsd-tdep.h +++ b/gdb/i386-fbsd-tdep.h @@ -32,8 +32,9 @@ uint64_t i386_fbsd_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout); /* Implement the core_read_x86_xsave_layout gdbarch method. */ -bool i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch, - x86_xsave_layout &layout); +extern bool i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch, + bfd &cbfd, + x86_xsave_layout &layout); /* The format of the XSAVE extended area is determined by hardware. Cores store the XSAVE extended area in a NT_X86_XSTATE note that diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index efbde6a3ccf..3360e96f86c 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -1105,11 +1105,10 @@ i386_linux_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout) /* See i386-linux-tdep.h. */ bool -i386_linux_core_read_x86_xsave_layout (struct gdbarch *gdbarch, +i386_linux_core_read_x86_xsave_layout (struct gdbarch *gdbarch, bfd &cbfd, x86_xsave_layout &layout) { - return i386_linux_core_read_xsave_info (current_program_space->core_bfd (), - layout) != 0; + return i386_linux_core_read_xsave_info (&cbfd, layout) != 0; } /* See arch/x86-linux-tdesc.h. */ diff --git a/gdb/i386-linux-tdep.h b/gdb/i386-linux-tdep.h index de98256462a..3a0e056413f 100644 --- a/gdb/i386-linux-tdep.h +++ b/gdb/i386-linux-tdep.h @@ -47,6 +47,7 @@ extern uint64_t i386_linux_core_read_xsave_info (bfd *abfd, /* Implement the core_read_x86_xsave_layout gdbarch method. */ extern bool i386_linux_core_read_x86_xsave_layout (struct gdbarch *gdbarch, + bfd &cbfd, x86_xsave_layout &layout); extern int i386_linux_gregset_reg_offset[];