]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: support fs_base and gs_base for 32-bit inferiors on 64-bit kernels
authorMarkus Metzger <markus.t.metzger@intel.com>
Fri, 22 Nov 2019 15:55:14 +0000 (16:55 +0100)
committerMarkus Metzger <markus.t.metzger@intel.com>
Tue, 17 Dec 2019 14:37:30 +0000 (15:37 +0100)
On Linux 64-bit kernels provide fs_base and gs_base also for 32-bit
inferiors.  Add support for those registers.

Also check for HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE consistently.

Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
gdb/
* amd64-linux-nat.c (amd64_linux_gregset32_reg_offset): Add FS_BASE
and GS_BASE offsets.
* amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Check
HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE.
(amd64_linux_read_description): Enable segments if
HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE.
* i386-linux-tdep.c (i386_linux_gregset_reg_offset): Add -1 for
FS_BASE and GS_BASE offsets.
(i386_linux_read_description): Enable segments if
HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE.
* i386-linux-tdep.h (I386_LINUX_ORIG_EAX_REGNUM): Update.

Change-Id: I030b500a7a5b087452a78c3e0545d6e6e65146aa

gdb/amd64-linux-nat.c
gdb/amd64-linux-tdep.c
gdb/i386-linux-tdep.c
gdb/i386-linux-tdep.h

index d0328b677d598456909c817c6e9969dc9961645f..ce2e980ad4e20f153a323561b66c3c10620436c0 100644 (file)
@@ -85,6 +85,11 @@ static int amd64_linux_gregset32_reg_offset[] =
   -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512)  */
   -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512)  */
   -1,                            /* PKEYS register PKRU  */
+#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  FS_BASE * 8, GS_BASE * 8,      /* fs_base and gs_base  */
+#else
+  -1, -1,                        /* fs_base and gs_base  */
+#endif
   ORIG_RAX * 8                   /* "orig_eax"  */
 };
 \f
index 7ec08c7fc49ff24d6d438162da2e6084529460cc..918dbed617cfb876b259a0b2db456d7a2d0ee8bf 100644 (file)
@@ -98,7 +98,11 @@ int amd64_linux_gregset_reg_offset[] =
   -1,                          /* PKEYS register pkru  */
 
   /* End of hardware registers */
+#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
   21 * 8, 22 * 8,                    /* fs_base and gs_base.  */
+#else
+  -1, -1,                            /* fs_base and gs_base.  */
+#endif
   15 * 8                             /* "orig_rax" */
 };
 \f
@@ -1593,9 +1597,15 @@ amd64_linux_read_description (uint64_t xcr0_features_bit, bool is_x32)
        [(xcr0_features_bit & X86_XSTATE_PKRU) ? 1 : 0];
     }
 
+#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  const bool segment = true;
+#else
+  const bool segment = false;
+#endif
+
   if (*tdesc == NULL)
     *tdesc = amd64_create_target_description (xcr0_features_bit, is_x32,
-                                             true, true);
+                                             true, segment);
 
   return *tdesc;
 }
index 0f10686bc0145804cc470fc6aa6b074c9a2d42b7..9cb2cd16e55a05c13a009f306f74ff270a64aaf1 100644 (file)
@@ -609,6 +609,7 @@ int i386_linux_gregset_reg_offset[] =
   -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512)  */
   -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512)  */
   -1,                            /* PKRU register  */
+  -1, -1,                        /* fs_base and gs_base.  */
   11 * 4,                        /* "orig_eax"  */
 };
 
@@ -692,8 +693,14 @@ i386_linux_read_description (uint64_t xcr0)
     [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
     [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
 
+#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  const bool segment = true;
+#else
+  const bool segment = false;
+#endif
+
   if (*tdesc == NULL)
-    *tdesc = i386_create_target_description (xcr0, true, false);
+    *tdesc = i386_create_target_description (xcr0, true, segment);
 
   return *tdesc;
 }
index 4842d2162440ac42dde9cdb47cb9e1181f435a09..6b048c5ad44fd606918387a5a550cfbe2f266b0a 100644 (file)
@@ -29,7 +29,7 @@
 /* Register number for the "orig_eax" pseudo-register.  If this
    pseudo-register contains a value >= 0 it is interpreted as the
    system call number that the kernel is supposed to restart.  */
-#define I386_LINUX_ORIG_EAX_REGNUM (I386_PKRU_REGNUM + 1)
+#define I386_LINUX_ORIG_EAX_REGNUM (I386_GSBASE_REGNUM + 1)
 
 /* Total number of registers for GNU/Linux.  */
 #define I386_LINUX_NUM_REGS (I386_LINUX_ORIG_EAX_REGNUM + 1)