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 1FA8B394D884 for ; Wed, 16 Mar 2022 19:46:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1FA8B394D884 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 6CE3C1A84C82 for ; Wed, 16 Mar 2022 15:46:17 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [RFC PATCH 3/4] Update x86 FreeBSD architectures to support XSAVE offsets. Date: Wed, 16 Mar 2022 12:46:07 -0700 Message-Id: <20220316194608.89528-4-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220316194608.89528-1-jhb@FreeBSD.org> References: <20220316194608.89528-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]); Wed, 16 Mar 2022 15:46:17 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.4 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: Wed, 16 Mar 2022 19:46:19 -0000 Add an implementation of gdbarch_core_xfer_x86_xsave_offsets which uses the size of an existing NT_X86_XSTATE core dump to determine the offsets via i387_set_xsave_offsets. The XSAVE register set is now also marked as variable size. This is not quite correct (and in particular, the maximum ("collect") size still assumes the Intel layout. --- gdb/amd64-fbsd-tdep.c | 8 ++++++-- gdb/i386-fbsd-tdep.c | 33 +++++++++++++++++++++++++++++++-- gdb/i386-fbsd-tdep.h | 6 ++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c index da5c297902d..19a86d40203 100644 --- a/gdb/amd64-fbsd-tdep.c +++ b/gdb/amd64-fbsd-tdep.c @@ -28,6 +28,7 @@ #include "amd64-tdep.h" #include "amd64-fbsd-tdep.h" +#include "i387-tdep.h" #include "fbsd-tdep.h" #include "solib-svr4.h" #include "inferior.h" @@ -236,7 +237,8 @@ static const struct regset amd64fbsd_xstateregset = { NULL, amd64fbsd_supply_xstateregset, - amd64fbsd_collect_xstateregset + amd64fbsd_collect_xstateregset, + REGSET_VARIABLE_SIZE }; /* Iterate over core file register note sections. */ @@ -253,7 +255,7 @@ 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), + cb (".reg-xstate", X86_XSTATE_SSE_SIZE, X86_XSTATE_SIZE (tdep->xcr0), &amd64fbsd_xstateregset, "XSAVE extended state", cb_data); } @@ -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_offsets + (gdbarch, i386fbsd_core_xfer_x86_xsave_offsets); /* 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..577eed06321 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,31 @@ i386fbsd_core_read_xcr0 (bfd *abfd) return xcr0; } +/* Implement the core_xfer_x86_xsave_offsets gdbarch method. */ + +LONGEST +i386fbsd_core_xfer_x86_xsave_offsets (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; + + if (offset > sizeof (struct xsave_offsets)) + return -1; + + i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch); + struct xsave_offsets xsave_offsets; + i387_set_xsave_offsets (tdep->xcr0, bfd_section_size (xstate), &xsave_offsets); + + if (offset + len > sizeof (struct xsave_offsets)) + len = sizeof (struct xsave_offsets) - offset; + + memcpy (readbuf, ((gdb_byte *) &xsave_offsets) + offset, len); + return len; +} + /* Implement the core_read_description gdbarch method. */ static const struct target_desc * @@ -299,7 +325,8 @@ static const struct regset i386fbsd_xstateregset = { NULL, i386fbsd_supply_xstateregset, - i386fbsd_collect_xstateregset + i386fbsd_collect_xstateregset, + REGSET_VARIABLE_SIZE }; /* Iterate over core file register note sections. */ @@ -318,7 +345,7 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch, NULL, cb_data); if (tdep->xcr0 & X86_XSTATE_AVX) - cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), + cb (".reg-xstate", X86_XSTATE_SSE_SIZE, X86_XSTATE_SIZE (tdep->xcr0), &i386fbsd_xstateregset, "XSAVE extended state", cb_data); } @@ -372,6 +399,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_offsets + (gdbarch, i386fbsd_core_xfer_x86_xsave_offsets); /* 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..ed8e8285f88 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_offsets gdbarch method. */ +extern LONGEST i386fbsd_core_xfer_x86_xsave_offsets (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