From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id 3B7AA386EC0E for ; Thu, 17 Mar 2022 18:37:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B7AA386EC0E 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.com (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id 6AF601A84E62; Thu, 17 Mar 2022 14:37:33 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Cc: Willgerodt, Felix Subject: [RFC PATCH v2 3/5] Update x86 FreeBSD architectures to support XSAVE layouts. Date: Thu, 17 Mar 2022 11:36:01 -0700 Message-Id: <20220317183603.34789-4-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220317183603.34789-1-jhb@FreeBSD.org> References: <20220317183603.34789-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]); Thu, 17 Mar 2022 14:37:33 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.3 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2022 18:37:35 -0000 Add an implementation of gdbarch_core_xfer_x86_xsave_layout which uses the size of an existing NT_X86_XSTATE core dump to determine the offsets via i387_set_xsave_layout. Use tdep->xsave_layout.sizeof_xsave as the size of the XSTATE register set and only fetch/store the register set if this size is non-zero. --- gdb/amd64-fbsd-tdep.c | 8 ++++++-- gdb/i386-fbsd-tdep.c | 37 ++++++++++++++++++++++++++++++++++--- gdb/i386-fbsd-tdep.h | 6 ++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c index da5c297902d..37d89c98bc9 100644 --- a/gdb/amd64-fbsd-tdep.c +++ b/gdb/amd64-fbsd-tdep.c @@ -253,8 +253,10 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, &amd64_fbsd_gregset, NULL, cb_data); cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &amd64_fpregset, NULL, cb_data); - cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), X86_XSTATE_SIZE (tdep->xcr0), - &amd64fbsd_xstateregset, "XSAVE extended state", cb_data); + if (tdep->xsave_layout.sizeof_xsave != 0) + cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave, + tdep->xsave_layout.sizeof_xsave, &amd64fbsd_xstateregset, + "XSAVE extended state", cb_data); } /* Implement the get_thread_local_address gdbarch method. */ @@ -295,6 +297,8 @@ amd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) tramp_frame_prepend_unwinder (gdbarch, &amd64_fbsd_sigframe); tdep->xsave_xcr0_offset = I386_FBSD_XSAVE_XCR0_OFFSET; + set_gdbarch_core_xfer_x86_xsave_layout + (gdbarch, i386fbsd_core_xfer_x86_xsave_layout); /* Iterate over core file register note sections. */ set_gdbarch_iterate_over_regset_sections diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c index 16ffd576323..cbbd3dcdc5f 100644 --- a/gdb/i386-fbsd-tdep.c +++ b/gdb/i386-fbsd-tdep.c @@ -18,6 +18,7 @@ along with this program. If not, see . */ #include "defs.h" +#include "gdbcore.h" #include "osabi.h" #include "regcache.h" #include "regset.h" @@ -263,6 +264,34 @@ i386fbsd_core_read_xcr0 (bfd *abfd) return xcr0; } +/* Implement the core_xfer_x86_xsave_layout gdbarch method. */ + +LONGEST +i386fbsd_core_xfer_x86_xsave_layout (struct gdbarch *gdbarch, + gdb_byte *readbuf, ULONGEST offset, + ULONGEST len) +{ + asection *xstate = bfd_get_section_by_name (core_bfd, ".reg-xstate"); + if (xstate == nullptr) + return -1; + + size_t size = bfd_section_size (xstate); + if (size < X86_XSTATE_AVX_SIZE) + return -1; + + if (offset > sizeof (x86_xsave_layout)) + return -1; + + x86_xsave_layout layout; + i387_set_xsave_layout (i386fbsd_core_read_xcr0 (core_bfd), size, &layout); + + if (offset + len > sizeof (layout)) + len = sizeof (layout) - offset; + + memcpy (readbuf, ((gdb_byte *) &layout) + offset, len); + return len; +} + /* Implement the core_read_description gdbarch method. */ static const struct target_desc * @@ -317,9 +346,9 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, &i386_fpregset, NULL, cb_data); - if (tdep->xcr0 & X86_XSTATE_AVX) - cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), - X86_XSTATE_SIZE (tdep->xcr0), &i386fbsd_xstateregset, + if (tdep->xsave_layout.sizeof_xsave != 0) + cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave, + tdep->xsave_layout.sizeof_xsave, &i386fbsd_xstateregset, "XSAVE extended state", cb_data); } @@ -372,6 +401,8 @@ i386fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) i386_elf_init_abi (info, gdbarch); tdep->xsave_xcr0_offset = I386_FBSD_XSAVE_XCR0_OFFSET; + set_gdbarch_core_xfer_x86_xsave_layout + (gdbarch, i386fbsd_core_xfer_x86_xsave_layout); /* Iterate over core file register note sections. */ set_gdbarch_iterate_over_regset_sections diff --git a/gdb/i386-fbsd-tdep.h b/gdb/i386-fbsd-tdep.h index 76f4c20f657..305ef8416ed 100644 --- a/gdb/i386-fbsd-tdep.h +++ b/gdb/i386-fbsd-tdep.h @@ -25,6 +25,12 @@ /* Get XSAVE extended state xcr0 from core dump. */ extern uint64_t i386fbsd_core_read_xcr0 (bfd *abfd); +/* Implement the core_xfer_x86_xsave_layout gdbarch method. */ +extern LONGEST i386fbsd_core_xfer_x86_xsave_layout (struct gdbarch *gdbarch, + gdb_byte *readbuf, + ULONGEST offset, + ULONGEST len); + /* The format of the XSAVE extended area is determined by hardware. Cores store the XSAVE extended area in a NT_X86_XSTATE note that matches the layout on Linux. */ -- 2.34.1