From patchwork Sat Mar 23 16:35:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 87570 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 542923858435 for ; Sat, 23 Mar 2024 16:37:07 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id F007D385840F for ; Sat, 23 Mar 2024 16:35:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F007D385840F 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 F007D385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711211746; cv=none; b=b1IMggTX6g+Yxk5IMe3lrlCFwzQ1b5bkRLsg5fufGuzirelfKUWw/PALm5Cya7HKhKGG6pjfIUuA3C6nerMAFxWb3oPiK3dVDyxuhTQ9endXN8C11frnsegLvZzOh0Wk/KMCAeEv5KyW474Gzj3zoHC1u6NVdmeivZfLD+NrQ1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711211746; c=relaxed/simple; bh=hH3YNgD4XDH5IYKwDO76P82rCRevIlDgzJ0C8HRO9sE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Bp6bXBkmuebOr0i8Vnam9yxvultPP3vLvVSANvgMI9rOO36GaFHK3P6vCITzNy62Yf4g6gJc7AYQs53qQDoFqrVZqjEf+6K/Tz+4BdnDdYHMRNrGEbwmn7SwVKTGTZh+NdO8PATpdBTv2g81WzuYnITJ9bHcANGe5D2NTUxEoVg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711211742; 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=mPv8wUlIPJiHsLm7VbGVGs4nXwQEddc/JamEPU0vjuY=; b=Iiyft6WwlM3sYzqHSu55SS6juhmydrOM775UKNS1HkwIQ+ClWMVp3wliP0N0HpD5GV6U3Y RIWnLFhiPCJyrSAOcmkNj/bQQmDffT+U2zm148QYtd9YzYMLt+mNfETK1tcwg0h6EzaASo iRMYpBCesUQew6PuIEtuzOBdUFYfGGk= 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-307-HzZiF_6cNcqGgDeEM4hvHg-1; Sat, 23 Mar 2024 12:35:41 -0400 X-MC-Unique: HzZiF_6cNcqGgDeEM4hvHg-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a4748cfa0f6so23364766b.1 for ; Sat, 23 Mar 2024 09:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711211739; x=1711816539; 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=MESXLCqT5T4epsKKM7Vjsp8kP6SStrg9yZ2GZQjH1pg=; b=o0GHx9oSZx9hufNL9XRwPCnEsmjhJcbKTarbLqudW5FosyulX7w0jGHk1Ox6qIEuME orEg3DPXbD2f0W5ovxvtWK/aZ+C5qgHKran1CnlqPm+taWET+54e+Pb3MLjc3t5Q28vo ShyTc19Xhgl0WCQMSVb4kZvqqhlz11NfMJavRLww8Pad8YQgW55xq41KEPqfs/sK3znS YSMuR9+Se1ksFrXfYIPzcQ9Wzs8TXMt6cc7V+oCEMoAWbW0Te/e4qtX96olXUDvsjm9X JveQOIOVXmS3oFIxGVv1P4ui6uOC57fXgmcO8HdRz+Fob7Hd3esEqKT5SE0Nyi16veaW u1CA== X-Gm-Message-State: AOJu0Yyurd5ZirFGuBMm+KoxFA0rl7h2T8v7Hzz8f/iyNk7P4wNNYYDZ Xs6Xatx4YcNr49bptQH0aG4ovE2CFusN+5LpeBN15ZCvhyE8gQSA73y+H4YQOWcYFdTkMEmjFqQ vGnyDE+ZkvFA5+/tlUoVPZGq21zhLF6AoniF0o7vpNErU+tfwwlUQc19ftVyENjoDIL97eyiJFi gdNQOPMHDzQkF6uSIlFIZ6VuwbOXEk3d1MTJFbyhYpydY= X-Received: by 2002:a50:f692:0:b0:56b:ff60:3984 with SMTP id d18-20020a50f692000000b0056bff603984mr468219edn.9.1711211738832; Sat, 23 Mar 2024 09:35:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHy9/0Sxwe/TjeQe/VTGyouqXeBNrhgpvCIaQslBOKKqLR7J3tRJW7U+xpE9V/acEeVI9Vaug== X-Received: by 2002:a50:f692:0:b0:56b:ff60:3984 with SMTP id d18-20020a50f692000000b0056bff603984mr468206edn.9.1711211738183; Sat, 23 Mar 2024 09:35:38 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id r10-20020a508d8a000000b0056ba017ca7fsm994935edh.87.2024.03.23.09.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 09:35:37 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , hjl.tools@gmail.com, John Baldwin Subject: [PATCHv3 4/8] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Date: Sat, 23 Mar 2024 16:35:22 +0000 Message-Id: <85d9930527784778e52ddc7f633eb528ba606b41.1711211528.git.aburgess@redhat.com> 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 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. Approved-By: John Baldwin --- 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 872c3fc69c7..30d876efc5d 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. */