From patchwork Tue Mar 5 17:00:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86825 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 CC09338582A0 for ; Tue, 5 Mar 2024 17:01:35 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BF9E9385841E for ; Tue, 5 Mar 2024 17:00:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF9E9385841E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF9E9385841E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709658039; cv=none; b=a1d24QmsfFIIdRif2Fi3t9CEfy1+HRVkQepdBfyCVMqejlpze+PoFyvFGMIXW2+lS2hAhUP7U25fwNmJuQLxcu4cI+md7WlYmc6dvWwCyuRbRYs+Xcp4mMy+ggdxC+0hNMZ9iGhxFsT894pvLqe06dmy/M69pa9WjTaArzrqykc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709658039; c=relaxed/simple; bh=33soRsZkXSgzEHGChzLjEQIdtmxoK62AIEhTozwP8Ss=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=B+sRAtz8qpn2WX0oifceeMLtEl4GKYWi5yYBmtettfScYuq9qM/y+h4uR9BNk1NiREL7B8pYo9EyOC1/bmODhByfpBXuNsrPYntxUEyN4inPRUvp6KfeFdZcZfrN7TRnOavr/UseEQ84fuXpvj4cfSTv3wPN5V/O3DQWVCXm+u0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709658037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CJngwrA0jAT15OSINDaXUgDRUESbq+cA5MNEVZHqi6A=; b=cXJt9riY7j2enRSeLRQEqewr7F9mbYujsZhD+sNDxBPTGfu7qXCXj58hJ98lwKkAoy+pJE wCB6RQnuhl1JdV5o79Ru6LyAovvX/53S+tyeQu9D871YE43nqIzA6MB9mFoAUJHHs8wRdK Ih3VbjVzoJkd4qYh9XZR+QPYUhe9CV8= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-130-QIGWVH8_M4KPp4Dz694BFw-1; Tue, 05 Mar 2024 12:00:36 -0500 X-MC-Unique: QIGWVH8_M4KPp4Dz694BFw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a45851b0030so94250766b.3 for ; Tue, 05 Mar 2024 09:00:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709658035; x=1710262835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5l6cZBAwFHCFujU3vwfZPFJhWxmCp2WHrpaQ8yWZrUw=; b=EqCHCV61zx+YiIFaa/N5CsMPp9ISBoVAqDEDsok8R2JecQvNBe78BQ36zGbDdOxacB 2XtKvOqbsUhuudXuxK1VzHELaLyh3Ts4BA0dZt0PFTeDiqFaAkt6mIlvEt/KoCuv8ZjV AdyyLdtXhf+9kND+0aEgtMN1+JTNBWozetpS7jL+ShdomyQ8/2G8Te62kwTlpV36S7Su 1VyfpeR2asjIQgiOU5TSchYeCSuiRamIdhnpkZ3CBDcFYwZdweFpaC5u8Dn1IFjYOC73 K+aXExWgAWt9tPe8M1RMSS9yWMLTqDnjKIXAwCitGUG1tBDpkSGYR8U3lYCrshycTjyz rBkg== X-Gm-Message-State: AOJu0YzhxqiCgq3/Q7YFz7td/b9j5GJQQ1k8xsbEACy/yGeX3S8LHZ/l WS1bdFfNAFRA8eb7PQdcfnmpPKWS8iUBLtxabgn56t0Btgxy5FxxVnkeXDcBNkDBdU7zmPr59a3 l05GgaA+KDNq3+LWFSOThexUg66/xVPPtBSXwU661iGZKRpSCSb05mURvpzyjHGDFoRhlDnFUyp fpX4CZVj11r4f8eWJnTIModQDfKmKx74G4F25yY4cz1T4= X-Received: by 2002:a17:906:6b91:b0:a45:b2d0:87e6 with SMTP id l17-20020a1709066b9100b00a45b2d087e6mr224388ejr.44.1709658034556; Tue, 05 Mar 2024 09:00:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHl5PWCpP9MQbFnYd8jq20Cr4eteOwPhMMiszThtdzPjxZY8zTygJQ4/gf0UTKNlVT3nXbqQ== X-Received: by 2002:a17:906:6b91:b0:a45:b2d0:87e6 with SMTP id l17-20020a1709066b9100b00a45b2d087e6mr224364ejr.44.1709658033849; Tue, 05 Mar 2024 09:00:33 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id w18-20020a17090652d200b00a4320e22b31sm6304527ejn.19.2024.03.05.09.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 09:00:31 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 4/7] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Date: Tue, 5 Mar 2024 17:00:19 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 Share the definition of I386_LINUX_XSAVE_XCR0_OFFSET between GDB and gdbserver. This commit is part of a series that aims to share more of the x86 target description creation code between GDB and gdbserver. The I386_LINUX_XSAVE_XCR0_OFFSET #define is used as part of the target description creation, and I noticed that this constant is defined separately for GDB and gdbserver. This commit moves the definition into gdb/nat/x86-linux.h, which allows the #define to be shared. There should be no user visible changes after this commit. --- gdb/amd64-linux-tdep.c | 1 + gdb/i386-linux-tdep.c | 1 + gdb/i386-linux-tdep.h | 20 -------------------- gdb/nat/x86-linux.h | 20 ++++++++++++++++++++ gdbserver/linux-x86-low.cc | 22 +--------------------- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 1deb13b4e9a..a512ec5dd02 100644 --- a/gdb/amd64-linux-tdep.c +++ b/gdb/amd64-linux-tdep.c @@ -42,6 +42,7 @@ #include "arch/amd64.h" #include "target-descriptions.h" #include "expop.h" +#include "nat/x86-linux.h" /* The syscall's XML filename for i386. */ #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml" diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index a2f937690c2..8dd7203b6c3 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -40,6 +40,7 @@ #include "i387-tdep.h" #include "gdbsupport/x86-xstate.h" +#include "nat/x86-linux.h" /* The syscall's XML filename for i386. */ #define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml" diff --git a/gdb/i386-linux-tdep.h b/gdb/i386-linux-tdep.h index 5891747572b..07593c6a8ec 100644 --- a/gdb/i386-linux-tdep.h +++ b/gdb/i386-linux-tdep.h @@ -58,26 +58,6 @@ 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); -/* Format of XSAVE extended state is: - struct - { - fxsave_bytes[0..463] - sw_usable_bytes[464..511] - xstate_hdr_bytes[512..575] - extended state regions (AVX, MPX, AVX512, PKRU, etc.) - }; - - Same memory layout will be used for the coredump NT_X86_XSTATE - representing the XSAVE extended state registers. - - The first 8 bytes of the sw_usable_bytes[464..467] is the OS enabled - extended state mask, which is the same as the extended control register - 0 (the XFEATURE_ENABLED_MASK register), XCR0. We can use this mask - together with the mask saved in the xstate_hdr_bytes to determine what - states the processor/OS supports and what state, used or initialized, - the process/thread is in. */ -#define I386_LINUX_XSAVE_XCR0_OFFSET 464 - extern int i386_linux_gregset_reg_offset[]; /* Return x86 siginfo type. */ diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h index 15153ea277e..855a8d14f91 100644 --- a/gdb/nat/x86-linux.h +++ b/gdb/nat/x86-linux.h @@ -22,6 +22,26 @@ #include "nat/linux-nat.h" +/* Format of XSAVE extended state is: + struct + { + fxsave_bytes[0..463] + sw_usable_bytes[464..511] + xstate_hdr_bytes[512..575] + extended state regions (AVX, MPX, AVX512, PKRU, etc.) + }; + + Same memory layout will be used for the coredump NT_X86_XSTATE + representing the XSAVE extended state registers. + + The first 8 bytes of the sw_usable_bytes[464..467] is the OS enabled + extended state mask, which is the same as the extended control register + 0 (the XFEATURE_ENABLED_MASK register), XCR0. We can use this mask + together with the mask saved in the xstate_hdr_bytes to determine what + states the processor/OS supports and what state, used or initialized, + the process/thread is in. */ +#define I386_LINUX_XSAVE_XCR0_OFFSET 464 + /* Set whether our local mirror of LWP's debug registers has been changed since the values were last written to the thread. Nonzero indicates that a change has been made, zero indicates no change. */ diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc index ec80bfe905c..7bade8b3cbf 100644 --- a/gdbserver/linux-x86-low.cc +++ b/gdbserver/linux-x86-low.cc @@ -27,6 +27,7 @@ #include "gdbsupport/x86-xstate.h" #include "nat/x86-xstate.h" #include "nat/gdb_ptrace.h" +#include "nat/x86-linux.h" #ifdef __x86_64__ #include "nat/amd64-linux-siginfo.h" @@ -832,27 +833,6 @@ x86_target::low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction) static int use_xml; -/* Format of XSAVE extended state is: - struct - { - fxsave_bytes[0..463] - sw_usable_bytes[464..511] - xstate_hdr_bytes[512..575] - avx_bytes[576..831] - future_state etc - }; - - Same memory layout will be used for the coredump NT_X86_XSTATE - representing the XSAVE extended state registers. - - The first 8 bytes of the sw_usable_bytes[464..467] is the OS enabled - extended state mask, which is the same as the extended control register - 0 (the XFEATURE_ENABLED_MASK register), XCR0. We can use this mask - together with the mask saved in the xstate_hdr_bytes to determine what - states the processor/OS supports and what state, used or initialized, - the process/thread is in. */ -#define I386_LINUX_XSAVE_XCR0_OFFSET 464 - /* Does the current host support the GETFPXREGS request? The header file may or may not define it, and even if it is defined, the kernel will return EIO if it's running on a pre-SSE processor. */