Patchwork [20/25] Centralize amd64-linux target descriptions

login
register
mail settings
Submitter Yao Qi
Date June 12, 2017, 8:41 a.m.
Message ID <1497256916-4958-21-git-send-email-yao.qi@linaro.org>
Download mbox | patch
Permalink /patch/20932/
State New
Headers show

Comments

Yao Qi - June 12, 2017, 8:41 a.m.
This patch adds a new function amd64_linux_read_description, which
creates amd64-linux target descriptions according to its two
arguments, xcr0 and is_x32.

gdb:

2017-06-07  Yao Qi  <yao.qi@linaro.org>

	* amd64-linux-tdep.c (amd64_linux_read_description): New
	function.
	(amd64_linux_core_read_description): Call
	amd64_linux_read_description.
	(amd64_linux_init_abi): Likewise.
	(amd64_x32_linux_init_abi): Likewise.
	* amd64-linux-tdep.h (amd64_linux_read_description): Declare.
	* x86-linux-nat.c (x86_linux_read_description): Call
	amd64_linux_read_description.
---
 gdb/amd64-linux-tdep.c | 51 +++++++++++++++++++++++++++-----------------------
 gdb/amd64-linux-tdep.h |  6 ++++++
 gdb/x86-linux-nat.c    | 35 +---------------------------------
 3 files changed, 35 insertions(+), 57 deletions(-)

Patch

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 0e2f285..b9f624d 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -1575,54 +1575,59 @@  amd64_linux_record_signal (struct gdbarch *gdbarch,
   return 0;
 }
 
-/* Get Linux/x86 target description from core dump.  */
-
-static const struct target_desc *
-amd64_linux_core_read_description (struct gdbarch *gdbarch,
-				  struct target_ops *target,
-				  bfd *abfd)
+const target_desc *
+amd64_linux_read_description (uint64_t xcr0_features_bit, bool is_x32)
 {
-  /* Linux/x86-64.  */
-  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
-
-  switch (xcr0 & X86_XSTATE_ALL_MASK)
+  switch (xcr0_features_bit)
     {
     case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
-	  /* No MPX on x32, fallback to AVX-AVX512.  */
+      if (is_x32)
+	/* No MPX, PKU on x32, fall back to AVX-AVX512.  */
 	return tdesc_x32_avx_avx512_linux;
       else
 	return tdesc_amd64_avx_mpx_avx512_pku_linux;
     case X86_XSTATE_AVX_AVX512_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
 	return tdesc_x32_avx_avx512_linux;
       else
 	return tdesc_amd64_avx_avx512_linux;
     case X86_XSTATE_MPX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
-	  /* No MPX on x32, fallback to AVX-AVX512.  */
-	return tdesc_x32_avx_linux;
+      if (is_x32)
+	return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
       else
 	return tdesc_amd64_mpx_linux;
     case X86_XSTATE_AVX_MPX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
-	  /* No MPX on x32, fallback to AVX-AVX512.  */
-	return tdesc_x32_avx_linux;
+      if (is_x32)
+	return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
       else
 	return tdesc_amd64_avx_mpx_linux;
     case X86_XSTATE_AVX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
 	return tdesc_x32_avx_linux;
       else
 	return tdesc_amd64_avx_linux;
     default:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
 	return tdesc_x32_linux;
       else
 	return tdesc_amd64_linux;
     }
 }
 
+/* Get Linux/x86 target description from core dump.  */
+
+static const struct target_desc *
+amd64_linux_core_read_description (struct gdbarch *gdbarch,
+				  struct target_ops *target,
+				  bfd *abfd)
+{
+  /* Linux/x86-64.  */
+  uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
+
+  return amd64_linux_read_description (xcr0 & X86_XSTATE_ALL_MASK,
+				       gdbarch_ptr_bit (gdbarch) == 32);
+}
+
 /* Similar to amd64_supply_fpregset, but use XSAVE extended state.  */
 
 static void
@@ -1883,7 +1888,7 @@  amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
 
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_amd64_linux;
+    tdesc = amd64_linux_read_description (X86_XSTATE_SSE_MASK, false);
   tdep->tdesc = tdesc;
 
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
@@ -2100,7 +2105,7 @@  amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
 
   if (! tdesc_has_registers (tdesc))
-    tdesc = tdesc_x32_linux;
+    tdesc = amd64_linux_read_description (X86_XSTATE_SSE_MASK, true);
   tdep->tdesc = tdesc;
 
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
index 7453408..ab134a4 100644
--- a/gdb/amd64-linux-tdep.h
+++ b/gdb/amd64-linux-tdep.h
@@ -43,6 +43,12 @@  extern struct target_desc *tdesc_x32_linux;
 extern struct target_desc *tdesc_x32_avx_linux;
 extern struct target_desc *tdesc_x32_avx_avx512_linux;
 
+/* Return the right amd64-linux target descriptions according to
+   XCR0_FEATURES_BIT and IS_X32.  */
+
+const target_desc *amd64_linux_read_description (uint64_t xcr0_features_bit,
+						 bool is_x32);
+
 /* Enum that defines the syscall identifiers for amd64 linux.
    Used for process record/replay, these will be translated into
    a gdb-canonical set of syscall ids in linux-record.c.  */
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 2c4afb1..4611527 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -192,40 +192,7 @@  x86_linux_read_description (struct target_ops *ops)
   if (is_64bit)
     {
 #ifdef __x86_64__
-      switch (xcr0_features_bits)
-	{
-	case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-	  if (is_x32)
-	    /* No MPX, PKU on x32, fall back to AVX-AVX512.  */
-	    return tdesc_x32_avx_avx512_linux;
-	  else
-	    return tdesc_amd64_avx_mpx_avx512_pku_linux;
-	case X86_XSTATE_AVX_AVX512_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_avx512_linux;
-	  else
-	    return tdesc_amd64_avx_avx512_linux;
-	case X86_XSTATE_MPX_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
-	  else
-	    return tdesc_amd64_mpx_linux;
-	case X86_XSTATE_AVX_MPX_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_linux; /* No MPX on x32 using AVX.  */
-	  else
-	    return tdesc_amd64_avx_mpx_linux;
-	case X86_XSTATE_AVX_MASK:
-	  if (is_x32)
-	    return tdesc_x32_avx_linux;
-	  else
-	    return tdesc_amd64_avx_linux;
-	default:
-	  if (is_x32)
-	    return tdesc_x32_linux;
-	  else
-	    return tdesc_amd64_linux;
-	}
+      return amd64_linux_read_description (xcr0_features_bits, is_x32);
 #endif
     }
   else