From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mMIXKbSZcWL8GAQAWB0awg (envelope-from ) for ; Tue, 03 May 2022 17:08:04 -0400 Received: by simark.ca (Postfix, from userid 112) id A34E51E048; Tue, 3 May 2022 17:08:04 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 384D71E00E for ; Tue, 3 May 2022 17:08:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB90F385803D for ; Tue, 3 May 2022 21:08:03 +0000 (GMT) Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id A93D53857404 for ; Tue, 3 May 2022 21:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A93D53857404 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 E137C1A84E2E; Tue, 3 May 2022 17:06:12 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v3 07/13] gdb: Update x86 Linux architectures to support XSAVE layouts. Date: Tue, 3 May 2022 14:05:09 -0700 Message-Id: <20220503210515.30739-8-jhb@FreeBSD.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220503210515.30739-1-jhb@FreeBSD.org> References: <20220503210515.30739-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]); Tue, 03 May 2022 17:06:13 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean 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: , Cc: "George, Jini Susan" Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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. --- gdb/amd64-linux-tdep.c | 8 ++++++-- gdb/i386-linux-tdep.c | 34 ++++++++++++++++++++++++++++++++-- gdb/i386-linux-tdep.h | 6 ++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 0e5194fbeee..bb49224231d 100644 --- a/gdb/amd64-linux-tdep.c +++ b/gdb/amd64-linux-tdep.c @@ -1657,8 +1657,10 @@ amd64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, cb (".reg", 27 * 8, 27 * 8, &i386_gregset, NULL, cb_data); cb (".reg2", 512, 512, &amd64_fpregset, NULL, cb_data); - cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), X86_XSTATE_SIZE (tdep->xcr0), - &amd64_linux_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, &amd64_linux_xstateregset, + "XSAVE extended state", cb_data); } /* The instruction sequences used in x86_64 machines for a @@ -1800,6 +1802,8 @@ amd64_linux_init_abi_common(struct gdbarch_info info, struct gdbarch *gdbarch, tdep->sc_num_regs = ARRAY_SIZE (amd64_linux_sc_reg_offset); tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET; + set_gdbarch_core_xfer_x86_xsave_layout + (gdbarch, i386_linux_core_xfer_x86_xsave_layout); /* Add the %orig_rax register used for syscall restarting. */ set_gdbarch_write_pc (gdbarch, amd64_linux_write_pc); diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 5d7f54194af..52d4c7e395b 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -675,6 +675,34 @@ i386_linux_core_read_xcr0 (bfd *abfd) return xcr0; } +/* Implement the core_xfer_x86_xsave_layout gdbarch method. */ + +LONGEST +i386_linux_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 (i386_linux_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; +} + /* See i386-linux-tdep.h. */ const struct target_desc * @@ -768,8 +796,8 @@ i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, cb (".reg", 68, 68, &i386_gregset, NULL, cb_data); if (tdep->xcr0 & X86_XSTATE_AVX) - cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0), - X86_XSTATE_SIZE (tdep->xcr0), &i386_linux_xstateregset, + cb (".reg-xstate", tdep->xsave_layout.sizeof_xsave, + tdep->xsave_layout.sizeof_xsave, &i386_linux_xstateregset, "XSAVE extended state", cb_data); else if (tdep->xcr0 & X86_XSTATE_SSE) cb (".reg-xfp", 512, 512, &i386_fpregset, "extended floating-point", @@ -872,6 +900,8 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset); tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET; + set_gdbarch_core_xfer_x86_xsave_layout + (gdbarch, i386_linux_core_xfer_x86_xsave_layout); set_gdbarch_process_record (gdbarch, i386_process_record); set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal); diff --git a/gdb/i386-linux-tdep.h b/gdb/i386-linux-tdep.h index 6b3555aa3ea..02664d2d3b9 100644 --- a/gdb/i386-linux-tdep.h +++ b/gdb/i386-linux-tdep.h @@ -37,6 +37,12 @@ /* Get XSAVE extended state xcr0 from core dump. */ extern uint64_t i386_linux_core_read_xcr0 (bfd *abfd); +/* Implement the core_xfer_x86_xsave_layout gdbarch method. */ +extern LONGEST i386_linux_core_xfer_x86_xsave_layout (struct gdbarch *gdbarch, + gdb_byte *readbuf, + ULONGEST offset, + ULONGEST len); + /* Handle and display information related to the MPX bound violation to the user. */ extern void i386_linux_report_signal_info (struct gdbarch *gdbarch, -- 2.34.1