From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 7FA6E3858022 for ; Mon, 9 Oct 2023 18:36:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FA6E3858022 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.baldwin.net (unknown [98.47.15.113]) by mail.baldwin.cx (Postfix) with ESMTPSA id 66B7C1A84E2F; Mon, 9 Oct 2023 14:36:45 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt, Felix , George, Jini Susan , Simon Marchi 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 Message-ID: <20231009183617.24862-8-jhb@FreeBSD.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009183617.24862-1-jhb@FreeBSD.org> References: <20231009183617.24862-1-jhb@FreeBSD.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Mon, 09 Oct 2023 14:36:46 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_SHORT,KHOP_HELO_FCRDNS,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 . */ #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 *note_data, + int *note_size) +{ + gdb::optional 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 *note_data, + int *note_size); + #endif /* x86-tdep.h */ -- 2.41.0