public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
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 07/13] x86_elf_make_cpuid_note: Helper routine to build NT_X86_CPUID ELF note
Date: Mon,  9 Oct 2023 11:36:09 -0700	[thread overview]
Message-ID: <20231009183617.24862-8-jhb@FreeBSD.org> (raw)
In-Reply-To: <20231009183617.24862-1-jhb@FreeBSD.org>

Fetch the CPUID data from the current target via a new
TARGET_OBJECT_X86_CPUID and write it to an output bfd for a core dump.
---
 gdb/target.h   |  2 ++
 gdb/x86-tdep.c | 22 ++++++++++++++++++++++
 gdb/x86-tdep.h |  9 +++++++++
 3 files changed, 33 insertions(+)

diff --git a/gdb/target.h b/gdb/target.h
index 936ae79219c..c43cddde57c 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -210,6 +210,8 @@ enum target_object
   TARGET_OBJECT_FREEBSD_VMMAP,
   /* FreeBSD process strings.  */
   TARGET_OBJECT_FREEBSD_PS_STRINGS,
+  /* x86 CPUID leaves stored in NT_X86_CPUID core dump note.  */
+  TARGET_OBJECT_X86_CPUID,
   /* Possible future objects: TARGET_OBJECT_FILE, ...  */
 };
 
diff --git a/gdb/x86-tdep.c b/gdb/x86-tdep.c
index 6a73f2177c9..b36a86d8397 100644
--- a/gdb/x86-tdep.c
+++ b/gdb/x86-tdep.c
@@ -18,8 +18,11 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "elf-bfd.h"
+#include "inferior.h"
 #include "x86-tdep.h"
 #include "symtab.h"
+#include "target.h"
 
 
 /* Check whether NAME is included in NAMES[LO] (inclusive) to NAMES[HI]
@@ -75,3 +78,22 @@ x86_in_indirect_branch_thunk (CORE_ADDR pc, const char * const *register_names,
 
   return false;
 }
+
+/* See x86-tdep.h.  */
+
+void
+x86_elf_make_cpuid_note (bfd *obfd, gdb::unique_xmalloc_ptr<char> *note_data,
+			 int *note_size)
+{
+  gdb::optional<gdb::byte_vector> buf =
+    target_read_alloc (current_inferior ()->top_target (),
+		       TARGET_OBJECT_X86_CPUID, nullptr);
+  if (!buf || buf->empty ())
+    return;
+
+  note_data->reset (elfcore_write_register_note (obfd,
+						 note_data->release (),
+						 note_size,
+						 ".reg-x86-cpuid",
+						 buf->data (), buf->size ()));
+}
diff --git a/gdb/x86-tdep.h b/gdb/x86-tdep.h
index 7840ceda57d..6f210de7ad9 100644
--- a/gdb/x86-tdep.h
+++ b/gdb/x86-tdep.h
@@ -27,4 +27,13 @@ extern bool x86_in_indirect_branch_thunk (CORE_ADDR pc,
 					  const char * const *register_names,
 					  int lo, int hi);
 
+/* Add content to *NOTE_DATA (and update *NOTE_SIZE) to include a note
+   containing CPUID leaves for the current target.  The core file is
+   being written to OBFD.  If something goes wrong then *NOTE_DATA can
+   be set to nullptr.  */
+
+extern void x86_elf_make_cpuid_note (bfd *obfd,
+				     gdb::unique_xmalloc_ptr<char> *note_data,
+				     int *note_size);
+
 #endif /* x86-tdep.h */
-- 
2.41.0


  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 ` John Baldwin [this message]
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-8-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).