[PATCHv5,06/11] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition

Message ID d2b8729397add3ca1f195cc4619e5ea22408d010.1714143669.git.aburgess@redhat.com
State New
Headers
Series x86/Linux Target Description Changes |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Andrew Burgess April 26, 2024, 3:01 p.m. UTC
  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 gdbsupport/x86-xstate.h, which
allows the #define to be shared.

There should be no user visible changes after this commit.
---
 gdb/i386-linux-tdep.h      | 20 --------------------
 gdbserver/linux-x86-low.cc | 21 ---------------------
 gdbsupport/x86-xstate.h    | 20 ++++++++++++++++++++
 3 files changed, 20 insertions(+), 41 deletions(-)
  

Comments

Willgerodt, Felix April 29, 2024, 2:34 p.m. UTC | #1
> -----Original Message-----
> From: Andrew Burgess <aburgess@redhat.com>
> Sent: Freitag, 26. April 2024 17:02
> To: gdb-patches@sourceware.org
> Cc: Andrew Burgess <aburgess@redhat.com>; Willgerodt, Felix
> <felix.willgerodt@intel.com>; John Baldwin <jhb@FreeBSD.org>
> Subject: [PATCHv5 06/11] gdb/gdbserver: share
> I386_LINUX_XSAVE_XCR0_OFFSET definition
> 
> 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 gdbsupport/x86-xstate.h, which
> allows the #define to be shared.
> 
> There should be no user visible changes after this commit.
> ---
>  gdb/i386-linux-tdep.h      | 20 --------------------
>  gdbserver/linux-x86-low.cc | 21 ---------------------
>  gdbsupport/x86-xstate.h    | 20 ++++++++++++++++++++
>  3 files changed, 20 insertions(+), 41 deletions(-)
>

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>

Thanks,
Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

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/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
index ffb2a90731d..62612773a87 100644
--- a/gdbserver/linux-x86-low.cc
+++ b/gdbserver/linux-x86-low.cc
@@ -831,27 +831,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
-
 /* Get Linux/x86 target description from running target.  */
 
 static const struct target_desc *
diff --git a/gdbsupport/x86-xstate.h b/gdbsupport/x86-xstate.h
index 89c1143fbe1..11b37544aa3 100644
--- a/gdbsupport/x86-xstate.h
+++ b/gdbsupport/x86-xstate.h
@@ -120,4 +120,24 @@  constexpr bool operator!= (const x86_xsave_layout &lhs,
 
 #define I387_MXCSR_INIT_VAL 0x1f80
 
+/* 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
+
 #endif /* COMMON_X86_XSTATE_H */