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 06/13] nat/x86-cpuid: Add a function to build the contents of a NT_X86_CPUID note
Date: Mon, 9 Oct 2023 11:36:08 -0700 [thread overview]
Message-ID: <20231009183617.24862-7-jhb@FreeBSD.org> (raw)
In-Reply-To: <20231009183617.24862-1-jhb@FreeBSD.org>
---
gdb/nat/x86-cpuid.c | 91 +++++++++++++++++++++++++++++++++++++++++++++
gdb/nat/x86-cpuid.h | 7 ++++
2 files changed, 98 insertions(+)
create mode 100644 gdb/nat/x86-cpuid.c
diff --git a/gdb/nat/x86-cpuid.c b/gdb/nat/x86-cpuid.c
new file mode 100644
index 00000000000..a0fc9c2b192
--- /dev/null
+++ b/gdb/nat/x86-cpuid.c
@@ -0,0 +1,91 @@
+/* x86 CPUID functions.
+
+ Copyright (C) 2023 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "gdbsupport/common-defs.h"
+#include "nat/x86-cpuid.h"
+
+/* Data stored in the note for a single CPUID leaf. */
+
+struct cpuid_leaf
+{
+ uint32_t leaf;
+ uint32_t subleaf;
+ uint32_t eax;
+ uint32_t ebx;
+ uint32_t ecx;
+ uint32_t edx;
+};
+
+/* Append a single CPUID leaf. */
+
+static void
+append_cpuid_note (gdb::unique_xmalloc_ptr<gdb_byte> &buf, size_t &len,
+ uint32_t leaf, uint32_t subleaf)
+{
+ struct cpuid_leaf data;
+ if (!x86_cpuid_count (leaf, subleaf, &data.eax, &data.ebx, &data.ecx,
+ &data.edx))
+ return;
+
+ data.leaf = leaf;
+ data.subleaf = subleaf;
+
+ buf.reset ((gdb_byte *) xrealloc (buf.release (), len + sizeof (data)));
+ memcpy (buf.get() + len, &data, sizeof (data));
+ len += sizeof (data);
+}
+
+/* See x86-cpuid.h. */
+
+void
+x86_cpuid_note (gdb::unique_xmalloc_ptr<gdb_byte> &buf, size_t &len)
+{
+ buf.reset (nullptr);
+ len = 0;
+
+ /* Include 0xd sub-leaves that describe the XSAVE extended state. */
+ uint32_t eax, edx;
+ if (x86_cpuid_count (0xd, 0, &eax, nullptr, nullptr, &edx)
+ && (eax != 0 || edx != 0))
+ {
+ /* Main leaf and sub-leaf 1. */
+ append_cpuid_note (buf, len, 0xd, 0);
+ append_cpuid_note (buf, len, 0xd, 1);
+
+ /* Sub-leaves for each enabled feature. */
+ eax >>= 2;
+ uint32_t i = 2;
+ while (eax != 0)
+ {
+ if ((eax & 1) == 1)
+ append_cpuid_note (buf, len, 0xd, i);
+ eax >>= 1;
+ i++;
+ }
+
+ i = 0;
+ while (edx != 0)
+ {
+ if ((edx & 1) == 1)
+ append_cpuid_note (buf, len, 0xd, i + 32);
+ edx >>= 1;
+ i++;
+ }
+ }
+}
diff --git a/gdb/nat/x86-cpuid.h b/gdb/nat/x86-cpuid.h
index 9401705c44d..6b0561dfcf4 100644
--- a/gdb/nat/x86-cpuid.h
+++ b/gdb/nat/x86-cpuid.h
@@ -82,4 +82,11 @@ x86_cpuid_count (unsigned int __level, unsigned int __sublevel,
#undef nullptr
#endif
+#ifdef __cplusplus
+/* Store data for the NT_X86_CPUID core dump note in BUF for the current
+ host. The size of the data is stored in LEN. */
+
+void x86_cpuid_note (gdb::unique_xmalloc_ptr<gdb_byte> &buf, size_t &len);
+#endif
+
#endif /* NAT_X86_CPUID_H */
--
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 ` John Baldwin [this message]
2023-10-12 4:41 ` [RFC 06/13] nat/x86-cpuid: Add a function to build the contents of a NT_X86_CPUID note 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 ` [RFC 11/13] x86-linux-nat: Support fetching TARGET_OBJECT_X86_CPUID objects John Baldwin
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-7-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).