Centralize amd64-linux target descriptions
authorYao Qi <yao.qi@linaro.org>
Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)
committerYao Qi <yao.qi@linaro.org>
Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)
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-09-05  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/ChangeLog
gdb/amd64-linux-tdep.c
gdb/amd64-linux-tdep.h
gdb/x86-linux-nat.c

index f7f69fd29fd5fa539daac646e962eae17cc5adee..b17e48bcf99d97856f1f8eae94b5f0749c8a05c7 100644 (file)
@@ -1,3 +1,15 @@
+2017-09-05  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.
+
 2017-09-05  Yao Qi  <yao.qi@linaro.org>
 
        * amd64-linux-tdep.c (amd64_linux_core_read_description): Update
index 54c2eb9fdc4100ef9c38751ad08bbeb848c934d0..85efbefd1289bbe1770e5e55c185df0af69e15aa 100644 (file)
@@ -1575,54 +1575,61 @@ 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)
+      if (is_x32)
        /* No MPX, PKU on x32, fallback 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)
+      if (is_x32)
        /* No MPX on x32, fallback to AVX.  */
        return tdesc_x32_avx_linux;
       else
        return tdesc_amd64_mpx_linux;
     case X86_XSTATE_AVX_MPX_MASK:
-      if (gdbarch_ptr_bit (gdbarch) == 32)
+      if (is_x32)
        /* No MPX on x32, fallback to AVX.  */
        return tdesc_x32_avx_linux;
       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
@@ -1873,7 +1880,8 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset);
   tdep->sizeof_gregset = 27 * 8;
 
-  amd64_init_abi (info, gdbarch, tdesc_amd64_linux);
+  amd64_init_abi (info, gdbarch,
+                 amd64_linux_read_description (X86_XSTATE_SSE_MASK, false));
 
   const target_desc *tdesc = tdep->tdesc;
 
@@ -2086,7 +2094,9 @@ amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   tdep->gregset_num_regs = ARRAY_SIZE (amd64_linux_gregset_reg_offset);
   tdep->sizeof_gregset = 27 * 8;
 
-  amd64_x32_init_abi (info, gdbarch, tdesc_x32_linux);
+  amd64_x32_init_abi (info, gdbarch,
+                     amd64_linux_read_description (X86_XSTATE_SSE_MASK,
+                                                   true));
 
   /* Reserve a number for orig_rax.  */
   set_gdbarch_num_regs (gdbarch, AMD64_LINUX_NUM_REGS);
index 74534085a0b8ff5840fbb3ae9f266dacac88d563..ab134a45f8d0fef2404b4c2701d1bb40eecfa29b 100644 (file)
@@ -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.  */
index 2c4afb1f4bd4f0ff9f76f61c8a2e27305cc2aa6e..46115270581e580aeb2a9fb662fb366798d8beb9 100644 (file)
@@ -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