From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Cc: Willgerodt, Felix <felix.willgerodt@intel.com>
Subject: [RFC PATCH v2 3/5] Update x86 FreeBSD architectures to support XSAVE layouts.
Date: Thu, 17 Mar 2022 11:36:01 -0700 [thread overview]
Message-ID: <20220317183603.34789-4-jhb@FreeBSD.org> (raw)
In-Reply-To: <20220317183603.34789-1-jhb@FreeBSD.org>
Add an implementation of gdbarch_core_xfer_x86_xsave_layout which uses
the size of an existing NT_X86_XSTATE core dump to determine the
offsets via i387_set_xsave_layout.
Use tdep->xsave_layout.sizeof_xsave as the size of the XSTATE register
set and only fetch/store the register set if this size is non-zero.
---
gdb/amd64-fbsd-tdep.c | 8 ++++++--
gdb/i386-fbsd-tdep.c | 37 ++++++++++++++++++++++++++++++++++---
gdb/i386-fbsd-tdep.h | 6 ++++++
3 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index da5c297902d..37d89c98bc9 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -253,8 +253,10 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
&amd64_fbsd_gregset, NULL, cb_data);
cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &amd64_fpregset,
NULL, cb_data);
- cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), X86_XSTATE_SIZE (tdep->xcr0),
- &amd64fbsd_xstateregset, "XSAVE extended state", cb_data);
+ if (tdep->xsave_layout.sizeof_xsave != 0)
+ cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave,
+ tdep->xsave_layout.sizeof_xsave, &amd64fbsd_xstateregset,
+ "XSAVE extended state", cb_data);
}
/* Implement the get_thread_local_address gdbarch method. */
@@ -295,6 +297,8 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
tramp_frame_prepend_unwinder (gdbarch, &amd64_fbsd_sigframe);
tdep->xsave_xcr0_offset = I386_FBSD_XSAVE_XCR0_OFFSET;
+ set_gdbarch_core_xfer_x86_xsave_layout
+ (gdbarch, i386fbsd_core_xfer_x86_xsave_layout);
/* Iterate over core file register note sections. */
set_gdbarch_iterate_over_regset_sections
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index 16ffd576323..cbbd3dcdc5f 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -18,6 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include "gdbcore.h"
#include "osabi.h"
#include "regcache.h"
#include "regset.h"
@@ -263,6 +264,34 @@ i386fbsd_core_read_xcr0 (bfd *abfd)
return xcr0;
}
+/* Implement the core_xfer_x86_xsave_layout gdbarch method. */
+
+LONGEST
+i386fbsd_core_xfer_x86_xsave_layout (struct gdbarch *gdbarch,
+ gdb_byte *readbuf, ULONGEST offset,
+ ULONGEST len)
+{
+ asection *xstate = bfd_get_section_by_name (core_bfd, ".reg-xstate");
+ if (xstate == nullptr)
+ return -1;
+
+ size_t size = bfd_section_size (xstate);
+ if (size < X86_XSTATE_AVX_SIZE)
+ return -1;
+
+ if (offset > sizeof (x86_xsave_layout))
+ return -1;
+
+ x86_xsave_layout layout;
+ i387_set_xsave_layout (i386fbsd_core_read_xcr0 (core_bfd), size, &layout);
+
+ if (offset + len > sizeof (layout))
+ len = sizeof (layout) - offset;
+
+ memcpy (readbuf, ((gdb_byte *) &layout) + offset, len);
+ return len;
+}
+
/* Implement the core_read_description gdbarch method. */
static const struct target_desc *
@@ -317,9 +346,9 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &i386_fpregset,
NULL, cb_data);
- if (tdep->xcr0 & X86_XSTATE_AVX)
- cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
- X86_XSTATE_SIZE (tdep->xcr0), &i386fbsd_xstateregset,
+ if (tdep->xsave_layout.sizeof_xsave != 0)
+ cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave,
+ tdep->xsave_layout.sizeof_xsave, &i386fbsd_xstateregset,
"XSAVE extended state", cb_data);
}
@@ -372,6 +401,8 @@ i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
i386_elf_init_abi (info, gdbarch);
tdep->xsave_xcr0_offset = I386_FBSD_XSAVE_XCR0_OFFSET;
+ set_gdbarch_core_xfer_x86_xsave_layout
+ (gdbarch, i386fbsd_core_xfer_x86_xsave_layout);
/* Iterate over core file register note sections. */
set_gdbarch_iterate_over_regset_sections
diff --git a/gdb/i386-fbsd-tdep.h b/gdb/i386-fbsd-tdep.h
index 76f4c20f657..305ef8416ed 100644
--- a/gdb/i386-fbsd-tdep.h
+++ b/gdb/i386-fbsd-tdep.h
@@ -25,6 +25,12 @@
/* Get XSAVE extended state xcr0 from core dump. */
extern uint64_t i386fbsd_core_read_xcr0 (bfd *abfd);
+/* Implement the core_xfer_x86_xsave_layout gdbarch method. */
+extern LONGEST i386fbsd_core_xfer_x86_xsave_layout (struct gdbarch *gdbarch,
+ gdb_byte *readbuf,
+ ULONGEST offset,
+ ULONGEST len);
+
/* The format of the XSAVE extended area is determined by hardware.
Cores store the XSAVE extended area in a NT_X86_XSTATE note that
matches the layout on Linux. */
--
2.34.1
next prev parent reply other threads:[~2022-03-17 18:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-17 18:35 [RFC PATCH v2 0/5] Handle variable " John Baldwin
2022-03-17 18:35 ` [RFC PATCH v2 1/5] x86: Add an x86_xsave_layout structure to handle " John Baldwin
2022-03-17 18:36 ` [RFC PATCH v2 2/5] core: Support fetching TARGET_OBJECT_X86_XSAVE_LAYOUT from architectures John Baldwin
2022-03-28 11:28 ` George, Jini Susan
2022-03-17 18:36 ` John Baldwin [this message]
2022-03-17 18:36 ` [RFC PATCH v2 4/5] Support XSAVE layouts for the current host in the FreeBSD/amd64 target John Baldwin
2022-03-17 18:36 ` [RFC PATCH v2 5/5] x86: Use x86_xstate_layout to parse the XSAVE extended state area John Baldwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220317183603.34789-4-jhb@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=felix.willgerodt@intel.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).