From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Cc: Willgerodt, Felix <felix.willgerodt@intel.com>,
George, Jini Susan <JiniSusan.George@amd.com>,
Simon Marchi <simon.marchi@polymtl.ca>
Subject: [RFC 11/13] x86-linux-nat: Support fetching TARGET_OBJECT_X86_CPUID objects
Date: Mon, 9 Oct 2023 11:36:13 -0700 [thread overview]
Message-ID: <20231009183617.24862-12-jhb@FreeBSD.org> (raw)
In-Reply-To: <20231009183617.24862-1-jhb@FreeBSD.org>
When probing for the cached XSAVE layout, fetch the CPUID note data
and cache it until needed for a future fetch via ::xfer_partial.
---
gdb/configure.nat | 7 ++++---
gdb/x86-linux-nat.c | 37 +++++++++++++++++++++++++++++++++++++
gdb/x86-linux-nat.h | 9 +++++++++
3 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/gdb/configure.nat b/gdb/configure.nat
index 4ed71d8619d..c540e070dbb 100644
--- a/gdb/configure.nat
+++ b/gdb/configure.nat
@@ -255,8 +255,8 @@ case ${gdb_host} in
;;
i386)
# Host: Intel 386 running GNU/Linux.
- NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \
- nat/x86-xstate.o \
+ NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-cpuid.o \
+ nat/x86-dregs.o nat/x86-xstate.o \
i386-linux-nat.o x86-linux-nat.o nat/linux-btrace.o \
nat/x86-linux.o nat/x86-linux-dregs.o"
;;
@@ -321,7 +321,8 @@ case ${gdb_host} in
case ${gdb_host_cpu} in
i386)
# Host: GNU/Linux x86-64
- NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \
+ NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-cpuid.o \
+ nat/x86-dregs.o \
nat/x86-xstate.o amd64-nat.o amd64-linux-nat.o x86-linux-nat.o \
nat/linux-btrace.o \
nat/x86-linux.o nat/x86-linux-dregs.o \
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index cd8fd9c1dcd..517faccf934 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -36,6 +36,7 @@
#include "amd64-linux-tdep.h"
#endif
#include "gdbsupport/x86-xstate.h"
+#include "nat/x86-cpuid.h"
#include "nat/x86-xstate.h"
#include "nat/linux-btrace.h"
#include "nat/linux-nat.h"
@@ -182,6 +183,8 @@ x86_linux_nat_target::read_description ()
/ sizeof (uint64_t))];
m_xsave_layout = x86_fetch_xsave_layout (xcr0, x86_xsave_length ());
+
+ x86_cpuid_note (m_cpuid_note, m_cpuid_note_len);
}
}
@@ -213,6 +216,40 @@ x86_linux_nat_target::read_description ()
gdb_assert_not_reached ("failed to return tdesc");
}
+
+enum target_xfer_status
+x86_linux_nat_target::xfer_partial (enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len)
+{
+ switch (object)
+ {
+ case TARGET_OBJECT_X86_CPUID:
+ if (readbuf)
+ {
+ size_t size = m_cpuid_note_len;
+ if (offset >= size)
+ return TARGET_XFER_EOF;
+ size -= offset;
+ if (size > len)
+ size = len;
+
+ if (size == 0)
+ return TARGET_XFER_EOF;
+
+ memcpy (readbuf, m_cpuid_note.get () + offset, size);
+ *xfered_len = size;
+ return TARGET_XFER_OK;
+ }
+ return TARGET_XFER_E_IO;
+ default:
+ return linux_nat_target::xfer_partial (object, annex, readbuf,
+ writebuf, offset, len,
+ xfered_len);
+ }
+}
\f
/* Enable branch tracing. */
diff --git a/gdb/x86-linux-nat.h b/gdb/x86-linux-nat.h
index a0f8ffc993e..c2a6452ce27 100644
--- a/gdb/x86-linux-nat.h
+++ b/gdb/x86-linux-nat.h
@@ -45,6 +45,13 @@ struct x86_linux_nat_target : public x86_nat_target<linux_nat_target>
x86_xsave_layout fetch_x86_xsave_layout () override
{ return m_xsave_layout; }
+ enum target_xfer_status xfer_partial (enum target_object object,
+ const char *annex,
+ gdb_byte *readbuf,
+ const gdb_byte *writebuf,
+ ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_len) override;
+
/* These two are rewired to low_ versions. linux-nat.c queries
stopped-by-watchpoint info as soon as an lwp stops (via the low_
methods) and caches the result, to be returned via the normal
@@ -81,6 +88,8 @@ struct x86_linux_nat_target : public x86_nat_target<linux_nat_target>
private:
x86_xsave_layout m_xsave_layout;
+ gdb::unique_xmalloc_ptr<gdb_byte> m_cpuid_note;
+ size_t m_cpuid_note_len;
};
\f
--
2.41.0
next prev parent reply other threads:[~2023-10-09 18:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-09 18:36 [RFC 00/13] Proposal for a new NT_X86_CPUID core dump note John Baldwin
2023-10-09 18:36 ` [RFC 01/13] binutils: Support for the " John Baldwin
2023-10-16 9:23 ` Lancelot SIX
2023-10-16 23:23 ` John Baldwin
2023-10-09 18:36 ` [RFC 02/13] i387-tdep: Add function to read XSAVE layout from NT_X86_CPUID John Baldwin
2023-10-12 4:27 ` Simon Marchi
2023-10-16 23:52 ` John Baldwin
2023-10-16 9:17 ` Lancelot SIX
2023-10-17 0:04 ` John Baldwin
2023-10-09 18:36 ` [RFC 03/13] gdb: Use NT_X86_CPUID in x86 FreeBSD architectures to read XSAVE layouts John Baldwin
2023-10-09 18:36 ` [RFC 04/13] " John Baldwin
2023-10-12 4:28 ` Simon Marchi
2023-10-17 0:07 ` John Baldwin
2023-10-09 18:36 ` [RFC 05/13] nat/x86-cpuid.h: Remove non-x86 fallbacks John Baldwin
2023-10-12 4:29 ` Simon Marchi
2023-10-09 18:36 ` [RFC 06/13] nat/x86-cpuid: Add a function to build the contents of a NT_X86_CPUID note John Baldwin
2023-10-12 4:41 ` Simon Marchi
2023-10-17 0:22 ` John Baldwin
2023-10-09 18:36 ` [RFC 07/13] x86_elf_make_cpuid_note: Helper routine to build NT_X86_CPUID ELF note John Baldwin
2023-10-09 18:36 ` [RFC 08/13] x86-fbsd-nat: Support fetching TARGET_OBJECT_X86_CPUID objects John Baldwin
2023-10-09 18:36 ` [RFC 09/13] fbsd-tdep: Export fbsd_make_corefile_notes John Baldwin
2023-10-09 18:36 ` [RFC 10/13] {amd64,i386}-fbsd-tdep: Include NT_X86_CPUID notes in core dumps from gcore John Baldwin
2023-10-16 9:31 ` [RFC 10/13] {amd64, i386}-fbsd-tdep: " Lancelot SIX
2023-10-17 0:26 ` John Baldwin
2023-10-09 18:36 ` John Baldwin [this message]
2023-10-09 18:36 ` [RFC 12/13] linux-tdep: Export linux_make_corefile_notes John Baldwin
2023-10-09 18:36 ` [RFC 13/13] {amd64,i386}-linux-tdep: Include NT_X86_CPUID notes in core dumps from gcore John Baldwin
2023-10-10 16:30 ` [RFC 00/13] Proposal for a new NT_X86_CPUID core dump note George, Jini Susan
2023-10-12 4:01 ` Simon Marchi
2023-10-12 14:33 ` Simon Marchi
2023-10-12 17:18 ` John Baldwin
2023-10-13 9:38 ` George, Jini Susan
2023-10-17 0:36 ` John Baldwin
2023-10-26 16:18 ` George, Jini Susan
2023-10-27 2:53 ` John Baldwin
2023-10-27 11:11 ` George, Jini Susan
2023-10-31 16:41 ` 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=20231009183617.24862-12-jhb@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=JiniSusan.George@amd.com \
--cc=felix.willgerodt@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/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).