From patchwork Mon Oct 9 18:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77306 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3CD5386D604 for ; Mon, 9 Oct 2023 18:37:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 7A1BB3858408 for ; Mon, 9 Oct 2023 18:36:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A1BB3858408 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 80BD31A84E22; Mon, 9 Oct 2023 14:36:39 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 01/13] binutils: Support for the NT_X86_CPUID core dump note Date: Mon, 9 Oct 2023 11:36:03 -0700 Message-ID: <20231009183617.24862-2-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 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:40 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This core dump note contains an array of CPUID leaf values. Each entry in the array contains six 32-bit integers describing the inputs to the CPUID instruction (%eax and %ecx) and the outputs of the instruction (%eax, %ebx, %ecx, and %edx) similar to the C structure: struct cpuid_leaf { uint32_t leaf; uint32_t subleaf; uint32_t eax; uint32_t ebx; uint32_t ecx; uint32_t edx; }; Current implementations of this note contain leaves associated with the XSAVE state area (major leaf 0xd), but future implementations may add other leaf values in the future. --- bfd/elf-bfd.h | 2 ++ bfd/elf.c | 35 +++++++++++++++++++++++++++++++++++ binutils/readelf.c | 2 ++ include/elf/common.h | 2 ++ 4 files changed, 41 insertions(+) diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 335081ec629..235d0931ab4 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -2871,6 +2871,8 @@ extern char *elfcore_write_prxfpreg (bfd *, char *, int *, const void *, int); extern char *elfcore_write_xstatereg (bfd *, char *, int *, const void *, int); +extern char *elfcore_write_x86_cpuid + (bfd *, char *, int *, const void *, int); extern char *elfcore_write_x86_segbases (bfd *, char *, int *, const void *, int); extern char *elfcore_write_ppc_vmx diff --git a/bfd/elf.c b/bfd/elf.c index b5b0c69e097..35679821a49 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -10495,6 +10495,16 @@ elfcore_grok_xstatereg (bfd *abfd, Elf_Internal_Note *note) return elfcore_make_note_pseudosection (abfd, ".reg-xstate", note); } +/* Some systems dump an array of x86 cpuid leaves with a note type of + NT_X86_CPUID. Just include the whole note's contents + literally. */ + +static bool +elfcore_grok_x86_cpuid (bfd *abfd, Elf_Internal_Note *note) +{ + return elfcore_make_note_pseudosection (abfd, ".reg-x86-cpuid", note); +} + static bool elfcore_grok_ppc_vmx (bfd *abfd, Elf_Internal_Note *note) { @@ -11190,6 +11200,13 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) else return true; + case NT_X86_CPUID: + if (note->namesz == 6 + && strcmp (note->namedata, "LINUX") == 0) + return elfcore_grok_x86_cpuid (abfd, note); + else + return true; + case NT_PPC_VMX: if (note->namesz == 6 && strcmp (note->namedata, "LINUX") == 0) @@ -11768,6 +11785,9 @@ elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note) case NT_X86_XSTATE: return elfcore_grok_xstatereg (abfd, note); + case NT_X86_CPUID: + return elfcore_grok_x86_cpuid (abfd, note); + case NT_FREEBSD_PTLWPINFO: return elfcore_make_note_pseudosection (abfd, ".note.freebsdcore.lwpinfo", note); @@ -12640,6 +12660,19 @@ elfcore_write_xstatereg (bfd *abfd, char *buf, int *bufsiz, note_name, NT_X86_XSTATE, xfpregs, size); } +char * +elfcore_write_x86_cpuid (bfd *abfd, char *buf, int *bufsiz, + const void *cpuid, int size) +{ + char *note_name; + if (get_elf_backend_data (abfd)->elf_osabi == ELFOSABI_FREEBSD) + note_name = "FreeBSD"; + else + note_name = "LINUX"; + return elfcore_write_note (abfd, buf, bufsiz, + note_name, NT_X86_CPUID, cpuid, size); +} + char * elfcore_write_x86_segbases (bfd *abfd, char *buf, int *bufsiz, const void *regs, int size) @@ -13233,6 +13266,8 @@ elfcore_write_register_note (bfd *abfd, return elfcore_write_prxfpreg (abfd, buf, bufsiz, data, size); if (strcmp (section, ".reg-xstate") == 0) return elfcore_write_xstatereg (abfd, buf, bufsiz, data, size); + if (strcmp (section, ".reg-x86-cpuid") == 0) + return elfcore_write_x86_cpuid (abfd, buf, bufsiz, data, size); if (strcmp (section, ".reg-x86-segbases") == 0) return elfcore_write_x86_segbases (abfd, buf, bufsiz, data, size); if (strcmp (section, ".reg-ppc-vmx") == 0) diff --git a/binutils/readelf.c b/binutils/readelf.c index c9b6210e229..cb80aa6f396 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -20134,6 +20134,8 @@ get_note_type (Filedata * filedata, unsigned e_type) return _("NT_X86_XSTATE (x86 XSAVE extended state)"); case NT_X86_CET: return _("NT_X86_CET (x86 CET state)"); + case NT_X86_CPUID: + return _("NT_X86_CPUID (x86 CPUID leaves)"); case NT_S390_HIGH_GPRS: return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); case NT_S390_TIMER: diff --git a/include/elf/common.h b/include/elf/common.h index 244b13361e5..e8c6d753987 100644 --- a/include/elf/common.h +++ b/include/elf/common.h @@ -645,6 +645,8 @@ /* note name must be "LINUX". */ #define NT_X86_CET 0x203 /* x86 CET state. */ /* note name must be "LINUX". */ +#define NT_X86_CPUID 0x205 /* x86 CPUID leaves. */ + /* note name must be "LINUX". */ #define NT_S390_HIGH_GPRS 0x300 /* S/390 upper halves of GPRs */ /* note name must be "LINUX". */ #define NT_S390_TIMER 0x301 /* S390 timer */ From patchwork Mon Oct 9 18:36:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77302 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D6C1385E00F for ; Mon, 9 Oct 2023 18:37:01 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 29E443858C39 for ; Mon, 9 Oct 2023 18:36:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29E443858C39 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 735A01A84E24; Mon, 9 Oct 2023 14:36:40 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 02/13] i387-tdep: Add function to read XSAVE layout from NT_X86_CPUID Date: Mon, 9 Oct 2023 11:36:04 -0700 Message-ID: <20231009183617.24862-3-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 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:41 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This can be used by x86 arches to determine the XSAVE layout instead of guessing based on the XCR0 mask and XSAVE register note size. --- gdb/i387-tdep.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++ gdb/i387-tdep.h | 8 +++ 2 files changed, 140 insertions(+) diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c index 47667da21c7..1eac2b6bd2a 100644 --- a/gdb/i387-tdep.c +++ b/gdb/i387-tdep.c @@ -26,6 +26,8 @@ #include "target-float.h" #include "value.h" +#include + #include "i386-tdep.h" #include "i387-tdep.h" #include "gdbsupport/x86-xstate.h" @@ -987,6 +989,136 @@ i387_guess_xsave_layout (uint64_t xcr0, size_t xsave_size, return true; } +/* Parse a reg-x86-cpuid pseudo section building a hash table mapping + cpuid leaves to their results. */ + +struct cpuid_key +{ + cpuid_key (uint32_t _leaf, uint32_t _subleaf) + : leaf(_leaf), subleaf(_subleaf) + {} + + uint32_t leaf; + uint32_t subleaf; + + constexpr bool operator== (const cpuid_key &other) const + { return (leaf == other.leaf && subleaf == other.subleaf); } +}; + +namespace std +{ +template<> +struct hash +{ + size_t operator() (const cpuid_key &key) const + { + return key.leaf ^ (key.subleaf << 1); + } +}; +} + +struct cpuid_values +{ + cpuid_values (uint32_t _eax, uint32_t _ebx, uint32_t _ecx, uint32_t _edx) + : eax(_eax), ebx(_ebx), ecx(_ecx), edx(_edx) + {} + + uint32_t eax; + uint32_t ebx; + uint32_t ecx; + uint32_t edx; +}; + +typedef std::unordered_map cpuid_map; + +static cpuid_map +i387_parse_cpuid_from_core (bfd *bfd) +{ + asection *section = bfd_get_section_by_name (bfd, ".reg-x86-cpuid"); + if (section == nullptr) + return {}; + + size_t size = bfd_section_size (section); + if (size == 0 || (size % (6 * 4)) != 0) + return {}; + + char contents[size]; + if (!bfd_get_section_contents (bfd, section, contents, 0, size)) + { + warning (_("Couldn't read `.reg-x86-cpuid' section in core file.")); + return {}; + } + + cpuid_map map; + size_t index = 0; + while (index < size) + { + uint32_t leaf = bfd_get_32 (bfd, contents + index); + uint32_t count = bfd_get_32 (bfd, contents + index + 4); + uint32_t eax = bfd_get_32 (bfd, contents + index + 8); + uint32_t ebx = bfd_get_32 (bfd, contents + index + 12); + uint32_t ecx = bfd_get_32 (bfd, contents + index + 16); + uint32_t edx = bfd_get_32 (bfd, contents + index + 20); + + if (map.count (cpuid_key (leaf, count)) != 0) + { + warning (_("Duplicate cpuid leaf %#x,%#x"), leaf, count); + return {}; + } + map.emplace (cpuid_key (leaf, count), + cpuid_values (eax, ebx, ecx, edx)); + + index += 6 * 4; + } + + return map; +} + +/* Fetch the offset of a specific XSAVE extended region. */ + +static int +xsave_feature_offset (cpuid_map &map, uint64_t xcr0, int feature) +{ + if ((xcr0 & (1ULL << feature)) == 0) + return 0; + + return map.at (cpuid_key (0xd, feature)).ebx; +} + +/* See i387-tdep.h. */ + +bool +i387_read_xsave_layout_from_core (bfd *bfd, uint64_t xcr0, size_t xsave_size, + x86_xsave_layout &layout) +{ + cpuid_map map = i387_parse_cpuid_from_core (bfd); + if (map.empty ()) + return false; + + try + { + layout.sizeof_xsave = xsave_size; + layout.avx_offset = xsave_feature_offset (map, xcr0, + X86_XSTATE_AVX_ID); + layout.bndregs_offset = xsave_feature_offset (map, xcr0, + X86_XSTATE_BNDREGS_ID); + layout.bndcfg_offset = xsave_feature_offset (map, xcr0, + X86_XSTATE_BNDCFG_ID); + layout.k_offset = xsave_feature_offset (map, xcr0, + X86_XSTATE_K_ID); + layout.zmm_h_offset = xsave_feature_offset (map, xcr0, + X86_XSTATE_ZMM_H_ID); + layout.zmm_offset = xsave_feature_offset (map, xcr0, X86_XSTATE_ZMM_ID); + layout.pkru_offset = xsave_feature_offset (map, xcr0, X86_XSTATE_PKRU_ID); + } + catch (const std::out_of_range &) + { + return false; + } + + return true; +} + /* Extract from XSAVE a bitset of the features that are available on the target, but which have not yet been enabled. */ diff --git a/gdb/i387-tdep.h b/gdb/i387-tdep.h index e149e30e52e..b16b9a60b67 100644 --- a/gdb/i387-tdep.h +++ b/gdb/i387-tdep.h @@ -147,6 +147,14 @@ extern void i387_supply_fxsave (struct regcache *regcache, int regnum, extern bool i387_guess_xsave_layout (uint64_t xcr0, size_t xsave_size, x86_xsave_layout &layout); +/* Determine the XSAVE layout from the `reg-x86-cpuid` section in a + core dump. Returns true on sucess, or false if a layout can not be + read. */ + +extern bool i387_read_xsave_layout_from_core (bfd *bfd, uint64_t xcr0, + size_t xsave_size, + x86_xsave_layout &layout); + /* Similar to i387_supply_fxsave, but use XSAVE extended state. */ extern void i387_supply_xsave (struct regcache *regcache, int regnum, From patchwork Mon Oct 9 18:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77301 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E70D3857B9B for ; Mon, 9 Oct 2023 18:36:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 8EFD03858404 for ; Mon, 9 Oct 2023 18:36:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EFD03858404 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 7FA061A84E26; Mon, 9 Oct 2023 14:36:41 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 03/13] gdb: Use NT_X86_CPUID in x86 FreeBSD architectures to read XSAVE layouts Date: Mon, 9 Oct 2023 11:36:05 -0700 Message-ID: <20231009183617.24862-4-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 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:42 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org If this core dump note is present, use it to determine the layout of XSAVE register set notes. --- gdb/i386-fbsd-tdep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c index f8c2758c2b0..1789f3921fd 100644 --- a/gdb/i386-fbsd-tdep.c +++ b/gdb/i386-fbsd-tdep.c @@ -266,7 +266,8 @@ i386_fbsd_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout) uint64_t xcr0 = bfd_get_64 (abfd, contents); - if (!i387_guess_xsave_layout (xcr0, size, layout)) + if (!i387_read_xsave_layout_from_core (abfd, xcr0, size, layout) + && !i387_guess_xsave_layout (xcr0, size, layout)) return 0; return xcr0; From patchwork Mon Oct 9 18:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77303 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 69F11385CCB9 for ; Mon, 9 Oct 2023 18:37:13 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 99A753858407 for ; Mon, 9 Oct 2023 18:36:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99A753858407 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 861DE1A84E29; Mon, 9 Oct 2023 14:36:42 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 04/13] gdb: Use NT_X86_CPUID in x86 FreeBSD architectures to read XSAVE layouts Date: Mon, 9 Oct 2023 11:36:06 -0700 Message-ID: <20231009183617.24862-5-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 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:43 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org If this core dump note is present, use it to determine the layout of XSAVE register set notes. --- gdb/i386-linux-tdep.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 7ff7c155e2c..57d00a424d9 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -663,7 +663,8 @@ i386_linux_core_read_xsave_info (bfd *abfd, x86_xsave_layout &layout) uint64_t xcr0 = bfd_get_64 (abfd, contents); - if (!i387_guess_xsave_layout (xcr0, size, layout)) + if (!i387_read_xsave_layout_from_core (abfd, xcr0, size, layout) + && !i387_guess_xsave_layout (xcr0, size, layout)) return 0; return xcr0; From patchwork Mon Oct 9 18:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77304 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F146E385C6E2 for ; Mon, 9 Oct 2023 18:37:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 782153858402 for ; Mon, 9 Oct 2023 18:36:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 782153858402 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 77C961A84E2B; Mon, 9 Oct 2023 14:36:43 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 05/13] nat/x86-cpuid.h: Remove non-x86 fallbacks Date: Mon, 9 Oct 2023 11:36:07 -0700 Message-ID: <20231009183617.24862-6-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 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:44 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This header is only suitable for use on x86 hosts and is only included there, so these fallbacks should not be needed. --- gdb/nat/x86-cpuid.h | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/gdb/nat/x86-cpuid.h b/gdb/nat/x86-cpuid.h index e1b0321d593..9401705c44d 100644 --- a/gdb/nat/x86-cpuid.h +++ b/gdb/nat/x86-cpuid.h @@ -28,8 +28,6 @@ #define nullptr ((void *) 0) #endif -#if defined(__i386__) || defined(__x86_64__) - /* Return cpuid data for requested cpuid level, as found in returned eax, ebx, ecx and edx registers. The function checks if cpuid is supported and returns 1 for valid cpuid information or 0 for @@ -78,26 +76,6 @@ x86_cpuid_count (unsigned int __level, unsigned int __sublevel, return __get_cpuid_count (__level, __sublevel, __eax, __ebx, __ecx, __edx); } -#else - -static __inline int -x86_cpuid (unsigned int __level, - unsigned int *__eax, unsigned int *__ebx, - unsigned int *__ecx, unsigned int *__edx) -{ - return 0; -} - -static __inline int -x86_cpuid_count (unsigned int __level, unsigned int __sublevel, - unsigned int *__eax, unsigned int *__ebx, - unsigned int *__ecx, unsigned int *__edx) -{ - return 0; -} - -#endif /* i386 && x86_64 */ - #ifndef __cplusplus /* Avoid leaking this local definition beyond the scope of this header file. */ From patchwork Mon Oct 9 18:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77305 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14C0538560AA for ; Mon, 9 Oct 2023 18:37:28 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 7FDA83858414 for ; Mon, 9 Oct 2023 18:36:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FDA83858414 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 6CDBF1A84E2D; Mon, 9 Oct 2023 14:36:44 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi 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 Message-ID: <20231009183617.24862-7-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 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:45 -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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.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 . */ + +#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 &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 &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 &buf, size_t &len); +#endif + #endif /* NAT_X86_CPUID_H */ From patchwork Mon Oct 9 18:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77309 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 306233830B4C for ; Mon, 9 Oct 2023 18:37:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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@sourceware.org, Felix , George@sourceware.org, 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 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.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 . */ #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 */ From patchwork Mon Oct 9 18:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77307 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 933C738708CA for ; Mon, 9 Oct 2023 18:37:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 759B2385782B for ; Mon, 9 Oct 2023 18:36:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 759B2385782B 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 6CFDA1A84E35; Mon, 9 Oct 2023 14:36:46 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 08/13] x86-fbsd-nat: Support fetching TARGET_OBJECT_X86_CPUID objects Date: Mon, 9 Oct 2023 11:36:10 -0700 Message-ID: <20231009183617.24862-9-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 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:47 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.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 | 6 ++++-- gdb/x86-fbsd-nat.c | 37 +++++++++++++++++++++++++++++++++++++ gdb/x86-fbsd-nat.h | 9 +++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/gdb/configure.nat b/gdb/configure.nat index 1dc4206b69c..4ed71d8619d 100644 --- a/gdb/configure.nat +++ b/gdb/configure.nat @@ -165,7 +165,8 @@ case ${gdb_host} in ;; i386) # Host: FreeBSD/i386 - 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 x86-bsd-nat.o x86-fbsd-nat.o i386-fbsd-nat.o \ bsd-kvm.o" ;; @@ -195,7 +196,8 @@ case ${gdb_host} in i386) # Host: FreeBSD/amd64 NATDEPFILES="${NATDEPFILES} amd64-nat.o \ - amd64-fbsd-nat.o bsd-kvm.o x86-nat.o nat/x86-dregs.o \ + amd64-fbsd-nat.o bsd-kvm.o x86-nat.o nat/x86-cpuid.o \ + nat/x86-dregs.o \ nat/x86-xstate.o x86-bsd-nat.o x86-fbsd-nat.o" ;; esac diff --git a/gdb/x86-fbsd-nat.c b/gdb/x86-fbsd-nat.c index 240e228976c..14fd323a7fb 100644 --- a/gdb/x86-fbsd-nat.c +++ b/gdb/x86-fbsd-nat.c @@ -20,6 +20,7 @@ #include "defs.h" #include "x86-fbsd-nat.h" #ifdef PT_GETXSTATE_INFO +#include "nat/x86-cpuid.h" #include "nat/x86-xstate.h" #endif @@ -48,6 +49,40 @@ x86_fbsd_nat_target::low_new_fork (ptid_t parent, pid_t child) } #ifdef PT_GETXSTATE_INFO +enum target_xfer_status +x86_fbsd_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 fbsd_nat_target::xfer_partial (object, annex, readbuf, + writebuf, offset, len, + xfered_len); + } +} + void x86_fbsd_nat_target::probe_xsave_layout (pid_t pid) { @@ -56,6 +91,8 @@ x86_fbsd_nat_target::probe_xsave_layout (pid_t pid) m_xsave_probed = true; + x86_cpuid_note (m_cpuid_note, m_cpuid_note_len); + if (ptrace (PT_GETXSTATE_INFO, pid, (PTRACE_TYPE_ARG3) &m_xsave_info, sizeof (m_xsave_info)) != 0) return; diff --git a/gdb/x86-fbsd-nat.h b/gdb/x86-fbsd-nat.h index 723bb6cf305..71b6ad09916 100644 --- a/gdb/x86-fbsd-nat.h +++ b/gdb/x86-fbsd-nat.h @@ -42,6 +42,13 @@ class x86_fbsd_nat_target : public x86bsd_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; + protected: void probe_xsave_layout (pid_t pid); @@ -49,6 +56,8 @@ class x86_fbsd_nat_target : public x86bsd_nat_target x86_xsave_layout m_xsave_layout; private: + gdb::unique_xmalloc_ptr m_cpuid_note; + size_t m_cpuid_note_len; bool m_xsave_probed; #endif }; From patchwork Mon Oct 9 18:36:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77311 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B71B3875421 for ; Mon, 9 Oct 2023 18:37:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 6B5823858035 for ; Mon, 9 Oct 2023 18:36:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B5823858035 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 61B471A84E42; Mon, 9 Oct 2023 14:36:47 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 09/13] fbsd-tdep: Export fbsd_make_corefile_notes Date: Mon, 9 Oct 2023 11:36:11 -0700 Message-ID: <20231009183617.24862-10-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 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:48 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This permits FreeBSD architectures to override the gdbarch make_corefile_notes method to add architecture-specific notes. --- gdb/fbsd-tdep.c | 5 ++--- gdb/fbsd-tdep.h | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index d166d785736..ef7ea7cf8c3 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -667,10 +667,9 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize) return desc; } -/* Create appropriate note sections for a corefile, returning them in - allocated memory. */ +/* See fbsd-tdep.h. */ -static gdb::unique_xmalloc_ptr +gdb::unique_xmalloc_ptr fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) { gdb::unique_xmalloc_ptr note_data; diff --git a/gdb/fbsd-tdep.h b/gdb/fbsd-tdep.h index 65541a01a01..b457925c8a3 100644 --- a/gdb/fbsd-tdep.h +++ b/gdb/fbsd-tdep.h @@ -76,4 +76,11 @@ extern CORE_ADDR fbsd_get_thread_local_address (struct gdbarch *gdbarch, extern CORE_ADDR fbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc); + +/* Create appropriate note sections for a corefile, returning them in + allocated memory. */ + +extern gdb::unique_xmalloc_ptr fbsd_make_corefile_notes +(struct gdbarch *gdbarch, bfd *obfd, int *note_size); + #endif /* fbsd-tdep.h */ From patchwork Mon Oct 9 18:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77308 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 998F338346B7 for ; Mon, 9 Oct 2023 18:37:52 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 5C155385773C for ; Mon, 9 Oct 2023 18:36:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C155385773C 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 687091A84E44; Mon, 9 Oct 2023 14:36:48 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 10/13] {amd64, i386}-fbsd-tdep: Include NT_X86_CPUID notes in core dumps from gcore Date: Mon, 9 Oct 2023 11:36:12 -0700 Message-ID: <20231009183617.24862-11-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 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:49 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Override the gdbarch make_corefile_notes method for the FreeBSD x86 arches with a new function that calls fbsd_make_corefile_notes and x86_elf_make_cpuid_note to generate the core dump notes. --- gdb/amd64-fbsd-tdep.c | 1 + gdb/i386-fbsd-tdep.c | 15 +++++++++++++++ gdb/i386-fbsd-tdep.h | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c index 2b633cd479c..30cba8f6e6a 100644 --- a/gdb/amd64-fbsd-tdep.c +++ b/gdb/amd64-fbsd-tdep.c @@ -329,6 +329,7 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_core_read_description (gdbarch, amd64fbsd_core_read_description); + set_gdbarch_make_corefile_notes (gdbarch, i386_fbsd_make_corefile_notes); /* FreeBSD uses SVR4-style shared libraries. */ set_solib_svr4_fetch_link_map_offsets diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c index 1789f3921fd..810ecc90df1 100644 --- a/gdb/i386-fbsd-tdep.c +++ b/gdb/i386-fbsd-tdep.c @@ -26,6 +26,7 @@ #include "tramp-frame.h" #include "i386-fbsd-tdep.h" +#include "x86-tdep.h" #include "i386-tdep.h" #include "i387-tdep.h" #include "fbsd-tdep.h" @@ -370,6 +371,19 @@ i386fbsd_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, return fbsd_get_thread_local_address (gdbarch, dtv_addr, lm_addr, offset); } +/* See i386-fbsd-tdep.h. */ + +gdb::unique_xmalloc_ptr +i386_fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, + int *note_size) +{ + gdb::unique_xmalloc_ptr note_data = + fbsd_make_corefile_notes (gdbarch, obfd, note_size); + + x86_elf_make_cpuid_note (obfd, ¬e_data, note_size); + return note_data; +} + static void i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -403,6 +417,7 @@ i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_core_read_description (gdbarch, i386fbsd_core_read_description); + set_gdbarch_make_corefile_notes (gdbarch, i386_fbsd_make_corefile_notes); /* FreeBSD uses SVR4-style shared libraries. */ set_solib_svr4_fetch_link_map_offsets diff --git a/gdb/i386-fbsd-tdep.h b/gdb/i386-fbsd-tdep.h index c49cb1eba68..fc7bb1c521d 100644 --- a/gdb/i386-fbsd-tdep.h +++ b/gdb/i386-fbsd-tdep.h @@ -40,6 +40,13 @@ bool i386_fbsd_core_read_x86_xsave_layout (struct gdbarch *gdbarch, matches the layout on Linux. */ #define I386_FBSD_XSAVE_XCR0_OFFSET 464 +/* Create appropriate note sections for a corefile, returning them in + allocated memory. Extends fbsd_make_corefile_notes to add a + NT_X86_CPUID note. */ + +gdb::unique_xmalloc_ptr i386_fbsd_make_corefile_notes +(struct gdbarch *gdbarch, bfd *obfd, int *note_size); + extern const struct regset i386_fbsd_gregset; #endif /* i386-fbsd-tdep.h */ From patchwork Mon Oct 9 18:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77312 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 259F63861816 for ; Mon, 9 Oct 2023 18:38:07 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 6E02E385694E for ; Mon, 9 Oct 2023 18:36:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E02E385694E 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 5C0BA1A84E33; Mon, 9 Oct 2023 14:36:49 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 11/13] x86-linux-nat: Support fetching TARGET_OBJECT_X86_CPUID objects Date: Mon, 9 Oct 2023 11:36:13 -0700 Message-ID: <20231009183617.24862-12-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 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:50 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.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); + } +} /* 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 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 private: x86_xsave_layout m_xsave_layout; + gdb::unique_xmalloc_ptr m_cpuid_note; + size_t m_cpuid_note_len; }; From patchwork Mon Oct 9 18:36:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77310 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DC1C3831E27 for ; Mon, 9 Oct 2023 18:37:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 70546385843A for ; Mon, 9 Oct 2023 18:36:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70546385843A 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 658761A84E4D; Mon, 9 Oct 2023 14:36:50 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 12/13] linux-tdep: Export linux_make_corefile_notes Date: Mon, 9 Oct 2023 11:36:14 -0700 Message-ID: <20231009183617.24862-13-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 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:51 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This permits Linux architectures to override the gdbarch make_corefile_notes method to add architecture-specific notes. --- gdb/linux-tdep.c | 5 ++--- gdb/linux-tdep.h | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index f03a5b95332..1c9c09dbd71 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -2033,10 +2033,9 @@ linux_fill_prpsinfo (struct elf_internal_linux_prpsinfo *p) return 1; } -/* Build the note section for a corefile, and return it in a malloc - buffer. */ +/* See linux-tdep.h. */ -static gdb::unique_xmalloc_ptr +gdb::unique_xmalloc_ptr linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) { struct elf_internal_linux_prpsinfo prpsinfo; diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h index e09a6ef32b1..20807031e44 100644 --- a/gdb/linux-tdep.h +++ b/gdb/linux-tdep.h @@ -52,6 +52,13 @@ typedef char *(*linux_collect_thread_registers_ftype) (const struct regcache *, bfd *, char *, int *, enum gdb_signal); +/* Build the note section for a corefile, and return it in a malloc + buffer. */ + +gdb::unique_xmalloc_ptr linux_make_corefile_notes (struct gdbarch *gdbarch, + bfd *obfd, + int *note_size); + extern enum gdb_signal linux_gdb_signal_from_target (struct gdbarch *gdbarch, int signal); From patchwork Mon Oct 9 18:36:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 77313 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27080385F003 for ; Mon, 9 Oct 2023 18:38:21 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 985E53858024 for ; Mon, 9 Oct 2023 18:36:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 985E53858024 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 68FD51A84E4F; Mon, 9 Oct 2023 14:36:51 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt@sourceware.org, Felix , George@sourceware.org, Jini Susan , Simon Marchi Subject: [RFC 13/13] {amd64, i386}-linux-tdep: Include NT_X86_CPUID notes in core dumps from gcore Date: Mon, 9 Oct 2023 11:36:15 -0700 Message-ID: <20231009183617.24862-14-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 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:52 -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, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Override the gdbarch make_corefile_notes method for the Linux x86 arches with a new function that calls linux_make_corefile_notes and x86_elf_make_cpuid_note to generate the core dump notes. --- gdb/amd64-linux-tdep.c | 1 + gdb/i386-linux-tdep.c | 15 +++++++++++++++ gdb/i386-linux-tdep.h | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index e2fdf5fb6c8..11291a606b6 100644 --- a/gdb/amd64-linux-tdep.c +++ b/gdb/amd64-linux-tdep.c @@ -1838,6 +1838,7 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch, set_gdbarch_core_read_description (gdbarch, amd64_linux_core_read_description); + set_gdbarch_make_corefile_notes (gdbarch, i386_linux_make_corefile_notes); /* Displaced stepping. */ set_gdbarch_displaced_step_copy_insn (gdbarch, diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 57d00a424d9..6573fcd9ead 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -38,6 +38,7 @@ #include "xml-syscall.h" #include "infrun.h" +#include "x86-tdep.h" #include "i387-tdep.h" #include "gdbsupport/x86-xstate.h" @@ -827,6 +828,19 @@ i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch, return closure_; } +/* See i386-linux-tdep.h. */ + +gdb::unique_xmalloc_ptr +i386_linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, + int *note_size) +{ + gdb::unique_xmalloc_ptr note_data = + linux_make_corefile_notes (gdbarch, obfd, note_size); + + x86_elf_make_cpuid_note (obfd, ¬e_data, note_size); + return note_data; +} + static void i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -1068,6 +1082,7 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) (gdbarch, i386_linux_iterate_over_regset_sections); set_gdbarch_core_read_description (gdbarch, i386_linux_core_read_description); + set_gdbarch_make_corefile_notes (gdbarch, i386_linux_make_corefile_notes); /* Displaced stepping. */ set_gdbarch_displaced_step_copy_insn (gdbarch, diff --git a/gdb/i386-linux-tdep.h b/gdb/i386-linux-tdep.h index bd8e328b7fe..86ea96edd67 100644 --- a/gdb/i386-linux-tdep.h +++ b/gdb/i386-linux-tdep.h @@ -58,6 +58,13 @@ extern void i386_linux_report_signal_info (struct gdbarch *gdbarch, /* Return the target description according to XCR0. */ extern const struct target_desc *i386_linux_read_description (uint64_t xcr0); +/* Create appropriate note sections for a corefile, returning them in + allocated memory. Extends linux_make_corefile_notes to add a + NT_X86_CPUID note. */ + +extern gdb::unique_xmalloc_ptr i386_linux_make_corefile_notes +(struct gdbarch *gdbarch, bfd *obfd, int *note_size); + /* Format of XSAVE extended state is: struct {