public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver.
  2016-11-03  9:47 [PATCH 0/2] amd64: add fs_base and gs_base Walfred Tedeschi
@ 2016-11-03  9:47 ` Walfred Tedeschi
  2016-11-10 12:37   ` Gary Benson
  2016-11-03  9:47 ` [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
  2016-11-30 14:20 ` [PATCH 0/2] amd64: add fs_base and gs_base Gary Benson
  2 siblings, 1 reply; 13+ messages in thread
From: Walfred Tedeschi @ 2016-11-03  9:47 UTC (permalink / raw)
  To: palves, eliz, brobecker; +Cc: gdb-patches, Walfred Tedeschi

The macros mentioned in the title were set only for GDB. In gdbserver they
were not set until now.  To align the code in GDB and gdbserver these macros
are also added into gdbserver, enabling read and write of gs_base and fs_base
registers from the system in new and old kernels.

2016-10-27  Walfred Tedeschi  <walfred.tedeschi@intel.com>

gdb/gdbserver/ChangeLog:

    	* configure.ac: Check if the fs_base and gs_base members of
    	`struct user_regs_struct' exist.
    	* config.in: Regenerated.
    	* configure: Likewise.

---
 gdb/gdbserver/config.in    |  6 ++++++
 gdb/gdbserver/configure    | 26 ++++++++++++++++++++++++++
 gdb/gdbserver/configure.ac |  7 +++++++
 3 files changed, 39 insertions(+)

diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in
index b721ea8..34a7443 100644
--- a/gdb/gdbserver/config.in
+++ b/gdb/gdbserver/config.in
@@ -238,6 +238,12 @@
 /* Define to 1 if `struct stat' is a member of `st_blocks'. */
 #undef HAVE_STRUCT_STAT_ST_BLOCKS
 
+/* Define to 1 if `struct user_regs_struct' is a member of `fs_base'. */
+#undef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+
+/* Define to 1 if `struct user_regs_struct' is a member of `gs_base'. */
+#undef HAVE_STRUCT_USER_REGS_STRUCT_GS_BASE
+
 /* Define to 1 if the target supports __sync_*_compare_and_swap */
 #undef HAVE_SYNC_BUILTINS
 
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index bbce742..376ca9d 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -7591,6 +7591,32 @@ _ACEOF
 fi
 
 
+# See if <sys/user.h> supports the %fs_base and %gs_bas amd64 segment registers.
+# Older amd64 Linux's don't have the fs_base and gs_base members of
+# `struct user_regs_struct'.
+ac_fn_c_check_member "$LINENO" "struct user_regs_struct" "fs_base" "ac_cv_member_struct_user_regs_struct_fs_base" "#include <sys/user.h>
+"
+if test "x$ac_cv_member_struct_user_regs_struct_fs_base" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE 1
+_ACEOF
+
+
+fi
+ac_fn_c_check_member "$LINENO" "struct user_regs_struct" "gs_base" "ac_cv_member_struct_user_regs_struct_gs_base" "#include <sys/user.h>
+"
+if test "x$ac_cv_member_struct_user_regs_struct_gs_base" = x""yes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_USER_REGS_STRUCT_GS_BASE 1
+_ACEOF
+
+
+fi
+
+
+
 ac_fn_c_check_type "$LINENO" "socklen_t" "ac_cv_type_socklen_t" "#include <sys/types.h>
 #include <sys/socket.h>
 
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index 11d8c79..1c712dd 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -174,6 +174,13 @@ AC_CHECK_DECLS([strerror, perror, vasprintf, vsnprintf])
 
 AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
 
+# See if <sys/user.h> supports the %fs_base and %gs_bas amd64 segment registers.
+# Older amd64 Linux's don't have the fs_base and gs_base members of
+# `struct user_regs_struct'.
+AC_CHECK_MEMBERS([struct user_regs_struct.fs_base, struct user_regs_struct.gs_base],
+		 [], [], [#include <sys/user.h>])
+
+
 AC_CHECK_TYPES(socklen_t, [], [],
 [#include <sys/types.h>
 #include <sys/socket.h>
-- 
2.9.3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 0/2] amd64: add fs_base and gs_base
@ 2016-11-03  9:47 Walfred Tedeschi
  2016-11-03  9:47 ` [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver Walfred Tedeschi
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Walfred Tedeschi @ 2016-11-03  9:47 UTC (permalink / raw)
  To: palves, eliz, brobecker; +Cc: gdb-patches, Walfred Tedeschi

The next two patches add Linux system registers fs_base and gs_base
in GDB and gdbserver.

First commit align the gdbserver with GDB code  in terms of
HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE.

Second patch introduces the registers into GDB and gdbserver.


Walfred Tedeschi (2):
  gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for
    gdbserver.
  amd64-linux: expose system register FS_BASE and GS_BASE for Linux.

 gdb/amd64-linux-nat.c                       |  53 ++++++++
 gdb/amd64-linux-tdep.c                      |  35 ++++-
 gdb/amd64-linux-tdep.h                      |   2 +-
 gdb/amd64-tdep.h                            |   6 +-
 gdb/doc/gdb.texinfo                         |   3 +
 gdb/features/Makefile                       |  17 +--
 gdb/features/i386/64bit-segments.xml        |  12 ++
 gdb/features/i386/amd64-avx-linux.c         |  36 +++---
 gdb/features/i386/amd64-avx-linux.xml       |   1 +
 gdb/features/i386/amd64-avx-mpx-linux.c     |  48 +++----
 gdb/features/i386/amd64-avx-mpx-linux.xml   |   1 +
 gdb/features/i386/amd64-avx512-linux.c      | 192 ++++++++++++++--------------
 gdb/features/i386/amd64-avx512-linux.xml    |   1 +
 gdb/features/i386/amd64-linux.c             |   4 +
 gdb/features/i386/amd64-linux.xml           |   1 +
 gdb/features/i386/amd64-mpx-linux.c         |  16 ++-
 gdb/features/i386/amd64-mpx-linux.xml       |   1 +
 gdb/features/i386/x32-avx-linux.c           |  36 +++---
 gdb/features/i386/x32-avx-linux.xml         |   1 +
 gdb/features/i386/x32-avx512-linux.c        | 192 ++++++++++++++--------------
 gdb/features/i386/x32-avx512-linux.xml      |   1 +
 gdb/features/i386/x32-linux.c               |   4 +
 gdb/features/i386/x32-linux.xml             |   1 +
 gdb/gdbserver/config.in                     |   6 +
 gdb/gdbserver/configure                     |  26 ++++
 gdb/gdbserver/configure.ac                  |   7 +
 gdb/gdbserver/configure.srv                 |   2 +-
 gdb/gdbserver/linux-x86-low.c               |  32 +++++
 gdb/regformats/i386/amd64-avx-linux.dat     |   2 +
 gdb/regformats/i386/amd64-avx-mpx-linux.dat |   2 +
 gdb/regformats/i386/amd64-avx512-linux.dat  |   2 +
 gdb/regformats/i386/amd64-linux.dat         |   2 +
 gdb/regformats/i386/amd64-mpx-linux.dat     |   2 +
 gdb/regformats/i386/x32-avx-linux.dat       |   2 +
 gdb/regformats/i386/x32-avx512-linux.dat    |   2 +
 gdb/regformats/i386/x32-linux.dat           |   2 +
 gdb/testsuite/gdb.arch/amd64-gs_base.c      |  33 +++++
 gdb/testsuite/gdb.arch/amd64-gs_base.exp    |  57 +++++++++
 38 files changed, 582 insertions(+), 261 deletions(-)
 create mode 100644 gdb/features/i386/64bit-segments.xml
 create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.c
 create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.exp

-- 
2.9.3



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-03  9:47 [PATCH 0/2] amd64: add fs_base and gs_base Walfred Tedeschi
  2016-11-03  9:47 ` [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver Walfred Tedeschi
@ 2016-11-03  9:47 ` Walfred Tedeschi
  2016-11-05 14:55   ` John Baldwin
                     ` (2 more replies)
  2016-11-30 14:20 ` [PATCH 0/2] amd64: add fs_base and gs_base Gary Benson
  2 siblings, 3 replies; 13+ messages in thread
From: Walfred Tedeschi @ 2016-11-03  9:47 UTC (permalink / raw)
  To: palves, eliz, brobecker; +Cc: gdb-patches, Walfred Tedeschi

This patch allows examination of the registers FS_BASE and GS_BASE
for Linux Systems running on 64bit. Tests for simple read and write
of the new registers is also added with this patch.

Tests were performed on:
x86_64 RHEL 5.3     - For the older ptrace calls.
x86_64 Ubuntu 16.10 - For the new ptrace calls.

2016-04-26  Walfred Tedeschi  <walfred.tedeschi@intel.com>
	    Richard Henderson  <rth@redhat.com>

gdb/ChangeLog:

	* amd64-linux-nat.c (PTRACE_ARCH_PRCTL): New define.
	(amd64_linux_fetch_inferior_registers): Add case to fetch FS_BASE
	GS_BASE for older kernels.
	(amd64_linux_store_inferior_registers): Add case to store FS_BASE
	GS_BASE for older kernels.
	* amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Add FS_BASE
	and GS_BASE to the offset table.
	(amd64_linux_register_reggroup_p): Add FS_BASE and GS_BASE to the
	system register group.
	(amd64_linux_init_abi): Add the segment registers into
	the current target description.
	(amd64_x32_linux_init_abi): Add the segment registers into
	the target description.
	* amd64-tdep.h (amd64_regnum): Add AMD64_FSBASE_REGNUM and
	AMD64_GSBASE_REGNUM.
	(AMD64_NUM_REGS): Set to AMD64_GSBASE_REGNUM + 1.
	* amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Change the
	ORIG_RAX to be AMD64_NUM_REGS as defined in amd64-tdep.h.
	* features/Makefile (amd64-linux.dat, amd64-avx-linux.dat)
	(amd64-mpx-linux.dat, amd64-avx512-linux.dat, x32-linux.dat)
	(x32-avx-linux.dat, x32-avx512-linux.dat): Add
	i386/64bit-segments.xml in those rules.
	* features/i386/64bit-segments.xml: New file.
	* features/i386/amd64-avx-mpx-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx512-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-mpx-linux.xml: Add 64bit-segments.xml.
	* features/i386/x32-avx512-linux.xml: Add 64bit-segments.xml.
	* features/i386/x32-avx-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-linux.xml: Add 64bit-segments.xml.
	* features/i386/amd64-avx-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx-linux.c: Regenerated.
	* features/i386/amd64-avx-mpx.c: Regenerated.
	* features/i386/amd64-avx512-linux.c: Regenerated.
	* features/i386/amd64-linux.c: Regenerated.
	* features/i386/amd64-mpx-linux.c: Regenerated.
	* features/i386/i386-avx-mpx-linux.c: Regenerated.
	* features/i386/i386-avx-mpx.c: Regenerated.
	* features/i386/x32-avx-linux.c: Regenerated.
	* features/i386/x32-avx512-linux.c: Regenerated.

gdb/doc/ChangeLog:

	* gdb.texinfo (i386 Features): Add system segment registers
	as feature.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_64_regmap): Add fs_base and gs_base
	to the register table.
	(x86_fill_gregset): Add support for old kernels for the
	fs_base and gs_base system registers.
	(x86_store_gregset): Likewise.

gdb/testsuite/ChangeLog:

        * gdb.arch/amd64-gs_base.c: New file.
        * gdb.arch/amd64-gs_base.exp: New file.

---
 gdb/amd64-linux-nat.c                       |  53 ++++++++
 gdb/amd64-linux-tdep.c                      |  35 ++++-
 gdb/amd64-linux-tdep.h                      |   2 +-
 gdb/amd64-tdep.h                            |   6 +-
 gdb/doc/gdb.texinfo                         |   3 +
 gdb/features/Makefile                       |  17 +--
 gdb/features/i386/64bit-segments.xml        |  12 ++
 gdb/features/i386/amd64-avx-linux.c         |  36 +++---
 gdb/features/i386/amd64-avx-linux.xml       |   1 +
 gdb/features/i386/amd64-avx-mpx-linux.c     |  48 +++----
 gdb/features/i386/amd64-avx-mpx-linux.xml   |   1 +
 gdb/features/i386/amd64-avx512-linux.c      | 192 ++++++++++++++--------------
 gdb/features/i386/amd64-avx512-linux.xml    |   1 +
 gdb/features/i386/amd64-linux.c             |   4 +
 gdb/features/i386/amd64-linux.xml           |   1 +
 gdb/features/i386/amd64-mpx-linux.c         |  16 ++-
 gdb/features/i386/amd64-mpx-linux.xml       |   1 +
 gdb/features/i386/x32-avx-linux.c           |  36 +++---
 gdb/features/i386/x32-avx-linux.xml         |   1 +
 gdb/features/i386/x32-avx512-linux.c        | 192 ++++++++++++++--------------
 gdb/features/i386/x32-avx512-linux.xml      |   1 +
 gdb/features/i386/x32-linux.c               |   4 +
 gdb/features/i386/x32-linux.xml             |   1 +
 gdb/gdbserver/configure.srv                 |   2 +-
 gdb/gdbserver/linux-x86-low.c               |  32 +++++
 gdb/regformats/i386/amd64-avx-linux.dat     |   2 +
 gdb/regformats/i386/amd64-avx-mpx-linux.dat |   2 +
 gdb/regformats/i386/amd64-avx512-linux.dat  |   2 +
 gdb/regformats/i386/amd64-linux.dat         |   2 +
 gdb/regformats/i386/amd64-mpx-linux.dat     |   2 +
 gdb/regformats/i386/x32-avx-linux.dat       |   2 +
 gdb/regformats/i386/x32-avx512-linux.dat    |   2 +
 gdb/regformats/i386/x32-linux.dat           |   2 +
 gdb/testsuite/gdb.arch/amd64-gs_base.c      |  33 +++++
 gdb/testsuite/gdb.arch/amd64-gs_base.exp    |  57 +++++++++
 35 files changed, 543 insertions(+), 261 deletions(-)
 create mode 100644 gdb/features/i386/64bit-segments.xml
 create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.c
 create mode 100644 gdb/testsuite/gdb.arch/amd64-gs_base.exp

diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 5122b04..036e3a0 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -40,6 +40,11 @@
 #include "nat/linux-ptrace.h"
 #include "nat/amd64-linux-siginfo.h"
 
+/* This definition comes from prctl.h, but some kernels may not have it.  */
+#ifndef PTRACE_ARCH_PRCTL
+#define PTRACE_ARCH_PRCTL      30
+#endif
+
 /* Mapping between the general-purpose registers in GNU/Linux x86-64
    `struct user' format and GDB's register cache layout for GNU/Linux
    i386.
@@ -171,6 +176,30 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops,
 
 	  amd64_supply_fxsave (regcache, -1, &fpregs);
 	}
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
+	   fs_base and gs_base fields of user_regs_struct can be
+	   used directly.  */
+	unsigned long base;
+
+	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
+	  {
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_FS) < 0)
+	      perror_with_name (_("Couldn't get segment register fs_base"));
+
+	    regcache_raw_supply (regcache, AMD64_FSBASE_REGNUM, &base);
+	  }
+
+	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
+	  {
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, &base, ARCH_GET_GS) < 0)
+	      perror_with_name (_("Couldn't get segment register gs_base"));
+
+	    regcache_raw_supply (regcache, AMD64_GSBASE_REGNUM, &base);
+	  }
+      }
+#endif
     }
 }
 
@@ -237,6 +266,30 @@ amd64_linux_store_inferior_registers (struct target_ops *ops,
 	  if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0)
 	    perror_with_name (_("Couldn't write floating point status"));
 	}
+
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+	/* PTRACE_ARCH_PRCTL is obsolete since 2.6.25, where the
+	   fs_base and gs_base fields of user_regs_struct can be
+	   used directly.  */
+	void *base;
+
+	if (regnum == -1 || regnum == AMD64_FSBASE_REGNUM)
+	  {
+	    regcache_raw_collect (regcache, AMD64_FSBASE_REGNUM, &base);
+
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_FS) < 0)
+	      perror_with_name (_("Couldn't write fs_base"));
+	  }
+	if (regnum == -1 || regnum == AMD64_GSBASE_REGNUM)
+	  {
+
+	    regcache_raw_collect (regcache, AMD64_GSBASE_REGNUM, &base);
+	    if (ptrace (PTRACE_ARCH_PRCTL, tid, base, ARCH_SET_GS) < 0)
+	      perror_with_name (_("Couldn't write gs_base"));
+	  }
+      }
+#endif
     }
 }
 \f
diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 3f2a92b..a8a0b79 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
   -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
+  /* System register added at the end.  */
+#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
 
@@ -284,7 +291,9 @@ static int
 amd64_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 				 struct reggroup *group)
 { 
-  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM)
+  if (regnum == AMD64_LINUX_ORIG_RAX_REGNUM
+      || regnum == AMD64_FSBASE_REGNUM
+      || regnum == AMD64_GSBASE_REGNUM)
     return (group == system_reggroup
             || group == save_reggroup
             || group == restore_reggroup);
@@ -1872,6 +1881,18 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
     tdesc = tdesc_amd64_linux;
   tdep->tdesc = tdesc;
 
+  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
+  if (feature != NULL)
+    {
+      struct tdesc_arch_data *tdesc_data_segments
+      = (struct tdesc_arch_data *) info.tdep_info;
+
+      tdesc_numbered_register (feature, tdesc_data_segments,
+			       AMD64_FSBASE_REGNUM, "fs_base");
+      tdesc_numbered_register (feature, tdesc_data_segments,
+			       AMD64_GSBASE_REGNUM, "gs_base");
+    }
+
   feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
   if (feature == NULL)
     return;
@@ -2099,6 +2120,18 @@ amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   if (!valid_p)
     return;
 
+  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
+  if (feature != NULL)
+    {
+      struct tdesc_arch_data *tdesc_data
+      = (struct tdesc_arch_data *) info.tdep_info;
+
+      tdesc_numbered_register (feature, tdesc_data,
+			       AMD64_FSBASE_REGNUM, "fs_base");
+      tdesc_numbered_register (feature, tdesc_data,
+			       AMD64_GSBASE_REGNUM, "gs_base");
+    }
+
   amd64_linux_init_abi_common (info, gdbarch);
 
   /* Initialize the amd64_x32_linux_record_tdep.  */
diff --git a/gdb/amd64-linux-tdep.h b/gdb/amd64-linux-tdep.h
index d64d5d6..193d7b0 100644
--- a/gdb/amd64-linux-tdep.h
+++ b/gdb/amd64-linux-tdep.h
@@ -26,7 +26,7 @@
 /* Register number for the "orig_rax" register.  If this register
    contains a value >= 0 it is interpreted as the system call number
    that the kernel is supposed to restart.  */
-#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_ZMM31H_REGNUM + 1)
+#define AMD64_LINUX_ORIG_RAX_REGNUM (AMD64_NUM_REGS)
 
 /* Total number of registers for GNU/Linux.  */
 #define AMD64_LINUX_NUM_REGS (AMD64_LINUX_ORIG_RAX_REGNUM + 1)
diff --git a/gdb/amd64-tdep.h b/gdb/amd64-tdep.h
index 2691e99..548c5e7 100644
--- a/gdb/amd64-tdep.h
+++ b/gdb/amd64-tdep.h
@@ -76,13 +76,15 @@ enum amd64_regnum
   AMD64_K0_REGNUM,
   AMD64_K7_REGNUM = AMD64_K0_REGNUM + 7,
   AMD64_ZMM0H_REGNUM,
-  AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31
+  AMD64_ZMM31H_REGNUM = AMD64_ZMM0H_REGNUM + 31,
+  AMD64_FSBASE_REGNUM,
+  AMD64_GSBASE_REGNUM
 };
 
 /* Number of general purpose registers.  */
 #define AMD64_NUM_GREGS		24
 
-#define AMD64_NUM_REGS		(AMD64_ZMM31H_REGNUM + 1)
+#define AMD64_NUM_REGS		(AMD64_GSBASE_REGNUM + 1)
 
 extern struct target_desc *tdesc_amd64;
 
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index df548dc..d120aba 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -41116,6 +41116,9 @@ Memory Protection Extension (MPX).  It should describe the following registers:
 The @samp{org.gnu.gdb.i386.linux} feature is optional.  It should
 describe a single register, @samp{orig_eax}.
 
+The @samp{org.gnu.gdb.i386.segments} feature is optional.  It should
+describe two system registers: @samp{fs_base} and @samp{gs_base}.
+
 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
 @samp{org.gnu.gdb.i386.avx} feature.  It should
 describe additional @sc{xmm} registers:
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index 30eed5d..c87f29f 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -259,7 +259,7 @@ $(outdir)/i386/i386-linux.dat: i386/32bit-core.xml i386/32bit-sse.xml \
 			       i386/32bit-linux.xml
 $(outdir)/i386/amd64.dat: i386/64bit-core.xml i386/64bit-sse.xml
 $(outdir)/i386/amd64-linux.dat: i386/64bit-core.xml i386/64bit-sse.xml \
-			        i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/i386-avx.dat: i386/32bit-core.xml i386/32bit-avx.xml
 $(outdir)/i386/i386-avx-linux.dat: i386/32bit-core.xml i386/32bit-avx.xml \
 			       i386/32bit-linux.xml
@@ -279,11 +279,11 @@ $(outdir)/i386/i386-mmx.dat: i386/32bit-core.xml
 $(outdir)/i386/i386-mmx-linux.dat: i386/32bit-core.xml i386/32bit-linux.xml
 $(outdir)/i386/amd64-avx.dat: i386/64bit-core.xml i386/64bit-avx.xml
 $(outdir)/i386/amd64-avx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
-				    i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/amd64-mpx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
-			       i386/64bit-linux.xml i386/64bit-mpx.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml i386/64bit-mpx.xml
 $(outdir)/i386/amd64-avx-mpx-linux.dat: i386/64bit-core.xml \
-			       i386/64bit-linux.xml i386/64bit-mpx.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml i386/64bit-mpx.xml
 $(outdir)/i386/amd64-mpx.dat: i386/64bit-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml
 $(outdir)/i386/amd64-avx-mpx.dat: i386/64bit-core.xml \
@@ -292,17 +292,18 @@ $(outdir)/i386/amd64-avx512.dat: i386/64bit-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml i386/64bit-avx512.xml
 $(outdir)/i386/amd64-avx512-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml i386/64bit-avx512.xml \
-			       i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/x32.dat: i386/x32-core.xml i386/64bit-sse.xml
 $(outdir)/i386/x32-linux.dat: i386/x32-core.xml i386/64bit-sse.xml \
-			      i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/x32-avx.dat: i386/x32-core.xml i386/64bit-avx.xml
 $(outdir)/i386/x32-avx-linux.dat: i386/x32-core.xml i386/64bit-avx.xml \
-				  i386/64bit-linux.xml
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 $(outdir)/i386/x32-avx512.dat: i386/x32-core.xml i386/64bit-avx.xml \
 			       i386/64bit-mpx.xml i386/64bit-avx512.xml
 $(outdir)/i386/x32-avx512-linux.dat: i386/x32-core.xml i386/64bit-avx.xml \
-			       i386/64bit-mpx.xml i386/64bit-avx512.xml i386/64bit-linux.xml
+			       i386/64bit-mpx.xml i386/64bit-avx512.xml \
+			       i386/64bit-linux.xml i386/64bit-segments.xml
 
 # 'all' doesn't build the C files, so don't delete them in 'clean'
 # either.
diff --git a/gdb/features/i386/64bit-segments.xml b/gdb/features/i386/64bit-segments.xml
new file mode 100644
index 0000000..0ea55f5
--- /dev/null
+++ b/gdb/features/i386/64bit-segments.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2016 Free Software Foundation, Inc.
+
+     Copying and distribution of this file, with or without modification,
+     are permitted in any medium without royalty provided the copyright
+     notice and this notice are preserved.  -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.i386.segments">
+  <reg name="fs_base" bitsize="64" type="int" regnum="58"/>
+  <reg name="gs_base" bitsize="64" type="int" regnum="59"/>
+</feature>
diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
index 9c8f9eb..1d56dbf 100644
--- a/gdb/features/i386/amd64-avx-linux.c
+++ b/gdb/features/i386/amd64-avx-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   tdesc_amd64_avx_linux = result;
 }
diff --git a/gdb/features/i386/amd64-avx-linux.xml b/gdb/features/i386/amd64-avx-linux.xml
index adb3835..50ada07 100644
--- a/gdb/features/i386/amd64-avx-linux.xml
+++ b/gdb/features/i386/amd64-avx-linux.xml
@@ -14,5 +14,6 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
 </target>
diff --git a/gdb/features/i386/amd64-avx-mpx-linux.c b/gdb/features/i386/amd64-avx-mpx-linux.c
index 4605480..26c1339 100644
--- a/gdb/features/i386/amd64-avx-mpx-linux.c
+++ b/gdb/features/i386/amd64-avx-mpx-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx_mpx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
@@ -200,12 +204,12 @@ initialize_tdesc_amd64_avx_mpx_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
 
   tdesc_amd64_avx_mpx_linux = result;
 }
diff --git a/gdb/features/i386/amd64-avx-mpx-linux.xml b/gdb/features/i386/amd64-avx-mpx-linux.xml
index 526c700..ff47c03 100644
--- a/gdb/features/i386/amd64-avx-mpx-linux.xml
+++ b/gdb/features/i386/amd64-avx-mpx-linux.xml
@@ -14,6 +14,7 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
   <xi:include href="64bit-mpx.xml"/>
 </target>
diff --git a/gdb/features/i386/amd64-avx512-linux.c b/gdb/features/i386/amd64-avx512-linux.c
index ec3ba61..b071f62 100644
--- a/gdb/features/i386/amd64-avx512-linux.c
+++ b/gdb/features/i386/amd64-avx512-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_amd64_avx512_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
@@ -200,12 +204,12 @@ initialize_tdesc_amd64_avx512_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
   field_type = tdesc_named_type (feature, "ieee_single");
@@ -245,78 +249,78 @@ initialize_tdesc_amd64_avx512_linux (void)
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_create_vector (feature, "v2ui128", field_type, 2);
 
-  tdesc_create_reg (feature, "xmm16", 80, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 81, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 92, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 93, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 94, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 95, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 96, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 97, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 108, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 109, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 110, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 111, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 112, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 113, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 116, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 117, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 118, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 119, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 120, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 121, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 147, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 148, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 149, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 150, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
 
   tdesc_amd64_avx512_linux = result;
 }
diff --git a/gdb/features/i386/amd64-avx512-linux.xml b/gdb/features/i386/amd64-avx512-linux.xml
index f8eb35a..c154a0c 100644
--- a/gdb/features/i386/amd64-avx512-linux.xml
+++ b/gdb/features/i386/amd64-avx512-linux.xml
@@ -14,6 +14,7 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
   <xi:include href="64bit-mpx.xml"/>
   <xi:include href="64bit-avx512.xml"/>
diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
index 02aeba5..0e921ba9 100644
--- a/gdb/features/i386/amd64-linux.c
+++ b/gdb/features/i386/amd64-linux.c
@@ -151,5 +151,9 @@ initialize_tdesc_amd64_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   tdesc_amd64_linux = result;
 }
diff --git a/gdb/features/i386/amd64-linux.xml b/gdb/features/i386/amd64-linux.xml
index f665a5b..d0cd3e5 100644
--- a/gdb/features/i386/amd64-linux.xml
+++ b/gdb/features/i386/amd64-linux.xml
@@ -14,4 +14,5 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
 </target>
diff --git a/gdb/features/i386/amd64-mpx-linux.c b/gdb/features/i386/amd64-mpx-linux.c
index a20ca4f..e26a74a 100644
--- a/gdb/features/i386/amd64-mpx-linux.c
+++ b/gdb/features/i386/amd64-mpx-linux.c
@@ -151,6 +151,10 @@ initialize_tdesc_amd64_mpx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
   field_type = tdesc_named_type (feature, "uint64");
@@ -182,12 +186,12 @@ initialize_tdesc_amd64_mpx_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 58, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 59, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 60, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 61, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 62, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 63, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 60, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 61, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 62, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 63, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 64, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 65, 1, NULL, 64, "status");
 
   tdesc_amd64_mpx_linux = result;
 }
diff --git a/gdb/features/i386/amd64-mpx-linux.xml b/gdb/features/i386/amd64-mpx-linux.xml
index 835126b..074db32 100644
--- a/gdb/features/i386/amd64-mpx-linux.xml
+++ b/gdb/features/i386/amd64-mpx-linux.xml
@@ -14,5 +14,6 @@
   <xi:include href="64bit-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-mpx.xml"/>
 </target>
diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
index b12c71c..8406815 100644
--- a/gdb/features/i386/x32-avx-linux.c
+++ b/gdb/features/i386/x32-avx-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_x32_avx_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   tdesc_x32_avx_linux = result;
 }
diff --git a/gdb/features/i386/x32-avx-linux.xml b/gdb/features/i386/x32-avx-linux.xml
index 0cae967..21314a6 100644
--- a/gdb/features/i386/x32-avx-linux.xml
+++ b/gdb/features/i386/x32-avx-linux.xml
@@ -14,5 +14,6 @@
   <xi:include href="x32-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
 </target>
diff --git a/gdb/features/i386/x32-avx512-linux.c b/gdb/features/i386/x32-avx512-linux.c
index 7b2ab90..3994996 100644
--- a/gdb/features/i386/x32-avx512-linux.c
+++ b/gdb/features/i386/x32-avx512-linux.c
@@ -151,23 +151,27 @@ initialize_tdesc_x32_avx512_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx");
-  tdesc_create_reg (feature, "ymm0h", 58, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm1h", 59, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm2h", 60, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm3h", 61, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm4h", 62, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm5h", 63, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm6h", 64, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm7h", 65, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm8h", 66, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm9h", 67, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm10h", 68, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm11h", 69, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm12h", 70, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm13h", 71, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm14h", 72, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm15h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm0h", 60, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm1h", 61, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm2h", 62, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm3h", 63, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm4h", 64, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm5h", 65, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm6h", 66, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm7h", 67, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm8h", 68, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm9h", 69, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm10h", 70, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm11h", 71, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm12h", 72, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm13h", 73, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm14h", 74, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm15h", 75, 1, NULL, 128, "uint128");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.mpx");
   type = tdesc_create_struct (feature, "br128");
@@ -200,12 +204,12 @@ initialize_tdesc_x32_avx512_linux (void)
   field_type = tdesc_named_type (feature, "_bndcfgu");
   tdesc_add_field (type, "config", field_type);
 
-  tdesc_create_reg (feature, "bnd0raw", 74, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd1raw", 75, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd2raw", 76, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bnd3raw", 77, 1, NULL, 128, "br128");
-  tdesc_create_reg (feature, "bndcfgu", 78, 1, NULL, 64, "cfgu");
-  tdesc_create_reg (feature, "bndstatus", 79, 1, NULL, 64, "status");
+  tdesc_create_reg (feature, "bnd0raw", 76, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd1raw", 77, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd2raw", 78, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bnd3raw", 79, 1, NULL, 128, "br128");
+  tdesc_create_reg (feature, "bndcfgu", 80, 1, NULL, 64, "cfgu");
+  tdesc_create_reg (feature, "bndstatus", 81, 1, NULL, 64, "status");
 
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.avx512");
   field_type = tdesc_named_type (feature, "ieee_single");
@@ -245,78 +249,78 @@ initialize_tdesc_x32_avx512_linux (void)
   field_type = tdesc_named_type (feature, "uint128");
   tdesc_create_vector (feature, "v2ui128", field_type, 2);
 
-  tdesc_create_reg (feature, "xmm16", 80, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm17", 81, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm18", 82, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm19", 83, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm20", 84, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm21", 85, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm22", 86, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm23", 87, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm24", 88, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm25", 89, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm26", 90, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm27", 91, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm28", 92, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm29", 93, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm30", 94, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "xmm31", 95, 1, NULL, 128, "vec128");
-  tdesc_create_reg (feature, "ymm16h", 96, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm17h", 97, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm18h", 98, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm19h", 99, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm20h", 100, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm21h", 101, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm22h", 102, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm23h", 103, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm24h", 104, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm25h", 105, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm26h", 106, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm27h", 107, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm28h", 108, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm29h", 109, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm30h", 110, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "ymm31h", 111, 1, NULL, 128, "uint128");
-  tdesc_create_reg (feature, "k0", 112, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k1", 113, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k2", 114, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k3", 115, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k4", 116, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k5", 117, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k6", 118, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "k7", 119, 1, NULL, 64, "uint64");
-  tdesc_create_reg (feature, "zmm0h", 120, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm1h", 121, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm2h", 122, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm3h", 123, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm4h", 124, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm5h", 125, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm6h", 126, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm7h", 127, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm8h", 128, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm9h", 129, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm10h", 130, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm11h", 131, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm12h", 132, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm13h", 133, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm14h", 134, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm15h", 135, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm16h", 136, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm17h", 137, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm18h", 138, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm19h", 139, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm20h", 140, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm21h", 141, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm22h", 142, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm23h", 143, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm24h", 144, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm25h", 145, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm26h", 146, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm27h", 147, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm28h", 148, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm29h", 149, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm30h", 150, 1, NULL, 256, "v2ui128");
-  tdesc_create_reg (feature, "zmm31h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "xmm16", 82, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm17", 83, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm18", 84, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm19", 85, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm20", 86, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm21", 87, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm22", 88, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm23", 89, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm24", 90, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm25", 91, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm26", 92, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm27", 93, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm28", 94, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm29", 95, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm30", 96, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "xmm31", 97, 1, NULL, 128, "vec128");
+  tdesc_create_reg (feature, "ymm16h", 98, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm17h", 99, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm18h", 100, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm19h", 101, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm20h", 102, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm21h", 103, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm22h", 104, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm23h", 105, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm24h", 106, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm25h", 107, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm26h", 108, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm27h", 109, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm28h", 110, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm29h", 111, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm30h", 112, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "ymm31h", 113, 1, NULL, 128, "uint128");
+  tdesc_create_reg (feature, "k0", 114, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k1", 115, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k2", 116, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k3", 117, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k4", 118, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k5", 119, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k6", 120, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "k7", 121, 1, NULL, 64, "uint64");
+  tdesc_create_reg (feature, "zmm0h", 122, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm1h", 123, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm2h", 124, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm3h", 125, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm4h", 126, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm5h", 127, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm6h", 128, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm7h", 129, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm8h", 130, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm9h", 131, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm10h", 132, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm11h", 133, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm12h", 134, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm13h", 135, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm14h", 136, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm15h", 137, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm16h", 138, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm17h", 139, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm18h", 140, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm19h", 141, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm20h", 142, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm21h", 143, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm22h", 144, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm23h", 145, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm24h", 146, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm25h", 147, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm26h", 148, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm27h", 149, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm28h", 150, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm29h", 151, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm30h", 152, 1, NULL, 256, "v2ui128");
+  tdesc_create_reg (feature, "zmm31h", 153, 1, NULL, 256, "v2ui128");
 
   tdesc_x32_avx512_linux = result;
 }
diff --git a/gdb/features/i386/x32-avx512-linux.xml b/gdb/features/i386/x32-avx512-linux.xml
index 2056873..579be87 100644
--- a/gdb/features/i386/x32-avx512-linux.xml
+++ b/gdb/features/i386/x32-avx512-linux.xml
@@ -14,6 +14,7 @@
   <xi:include href="x32-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
   <xi:include href="64bit-avx.xml"/>
   <xi:include href="64bit-mpx.xml"/>
   <xi:include href="64bit-avx512.xml"/>
diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
index 1262688..ae49549 100644
--- a/gdb/features/i386/x32-linux.c
+++ b/gdb/features/i386/x32-linux.c
@@ -151,5 +151,9 @@ initialize_tdesc_x32_linux (void)
   feature = tdesc_create_feature (result, "org.gnu.gdb.i386.linux");
   tdesc_create_reg (feature, "orig_rax", 57, 1, NULL, 64, "int");
 
+  feature = tdesc_create_feature (result, "org.gnu.gdb.i386.segments");
+  tdesc_create_reg (feature, "fs_base", 58, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "gs_base", 59, 1, NULL, 64, "int");
+
   tdesc_x32_linux = result;
 }
diff --git a/gdb/features/i386/x32-linux.xml b/gdb/features/i386/x32-linux.xml
index 7311500..957aaf2 100644
--- a/gdb/features/i386/x32-linux.xml
+++ b/gdb/features/i386/x32-linux.xml
@@ -14,4 +14,5 @@
   <xi:include href="x32-core.xml"/>
   <xi:include href="64bit-sse.xml"/>
   <xi:include href="64bit-linux.xml"/>
+  <xi:include href="64bit-segments.xml"/>
 </target>
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 3267599..d03dcb9 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -35,7 +35,7 @@ ipa_x32_linux_regobj="x32-linux-ipa.o x32-avx-linux-ipa.o x32-avx512-linux-ipa.o
 ipa_ppc_linux_regobj="powerpc-32l-ipa.o powerpc-altivec32l-ipa.o powerpc-cell32l-ipa.o powerpc-vsx32l-ipa.o powerpc-isa205-32l-ipa.o powerpc-isa205-altivec32l-ipa.o powerpc-isa205-vsx32l-ipa.o powerpc-e500l-ipa.o powerpc-64l-ipa.o powerpc-altivec64l-ipa.o powerpc-cell64l-ipa.o powerpc-vsx64l-ipa.o powerpc-isa205-64l-ipa.o powerpc-isa205-altivec64l-ipa.o powerpc-isa205-vsx64l-ipa.o"
 
 srv_i386_32bit_xmlfiles="i386/32bit-core.xml i386/32bit-sse.xml i386/32bit-avx.xml i386/32bit-avx512.xml i386/32bit-mpx.xml"
-srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml"
+srv_i386_64bit_xmlfiles="i386/64bit-core.xml i386/64bit-segments.xml i386/64bit-sse.xml i386/64bit-avx.xml i386/64bit-avx512.xml i386/x32-core.xml i386/64bit-mpx.xml"
 srv_i386_xmlfiles="i386/i386.xml i386/i386-avx.xml i386/i386-avx512.xml i386/i386-mpx.xml i386/i386-avx-mpx.xml i386/i386-mmx.xml $srv_i386_32bit_xmlfiles"
 srv_amd64_xmlfiles="i386/amd64.xml i386/amd64-avx.xml i386/amd64-avx512.xml i386/x32.xml i386/x32-avx.xml i386/x32-avx512.xml i386/amd64-mpx.xml i386/amd64-avx-mpx.xml  $srv_i386_64bit_xmlfiles"
 srv_i386_linux_xmlfiles="i386/i386-linux.xml i386/i386-avx-linux.xml i386/i386-avx512-linux.xml i386/i386-mmx-linux.xml i386/32bit-linux.xml i386/i386-mpx-linux.xml i386/i386-avx-mpx-linux.xml $srv_i386_32bit_xmlfiles"
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index acded1a..53ea1f4 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -133,6 +133,11 @@ static const int x86_64_regmap[] =
   -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
   ORIG_RAX * 8,
+#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  21 * 8,  22 * 8,
+#else
+  -1, -1,
+#endif
   -1, -1, -1, -1,			/* MPX registers BND0 ... BND3.  */
   -1, -1,				/* MPX registers BNDCFGU, BNDSTATUS.  */
   -1, -1, -1, -1, -1, -1, -1, -1,       /* xmm16 ... xmm31 (AVX512)  */
@@ -306,6 +311,20 @@ x86_fill_gregset (struct regcache *regcache, void *buf)
       for (i = 0; i < X86_64_NUM_REGS; i++)
 	if (x86_64_regmap[i] != -1)
 	  collect_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
+
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+        unsigned long base;
+        int lwpid = lwpid_of (current_thread);
+
+        collect_register_by_name (regcache, "fs_base", &base);
+        ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_SET_FS);
+
+        collect_register_by_name (regcache, "gs_base", &base);
+        ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_SET_GS);
+      }
+#endif
+
       return;
     }
 
@@ -332,6 +351,19 @@ x86_store_gregset (struct regcache *regcache, const void *buf)
       for (i = 0; i < X86_64_NUM_REGS; i++)
 	if (x86_64_regmap[i] != -1)
 	  supply_register (regcache, i, ((char *) buf) + x86_64_regmap[i]);
+
+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+      {
+        unsigned long base;
+        int lwpid = lwpid_of (current_thread);
+
+        if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_FS) == 0)
+          supply_register_by_name (regcache, "fs_base", &base);
+
+        if (ptrace (PTRACE_ARCH_PRCTL, lwpid, &base, ARCH_GET_GS) == 0)
+          supply_register_by_name (regcache, "gs_base", &base);
+      }
+#endif
       return;
     }
 #endif
diff --git a/gdb/regformats/i386/amd64-avx-linux.dat b/gdb/regformats/i386/amd64-avx-linux.dat
index d8199da..7780b3b 100644
--- a/gdb/regformats/i386/amd64-avx-linux.dat
+++ b/gdb/regformats/i386/amd64-avx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/amd64-avx-mpx-linux.dat b/gdb/regformats/i386/amd64-avx-mpx-linux.dat
index 6d45324..7c2f928 100644
--- a/gdb/regformats/i386/amd64-avx-mpx-linux.dat
+++ b/gdb/regformats/i386/amd64-avx-mpx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/amd64-avx512-linux.dat b/gdb/regformats/i386/amd64-avx512-linux.dat
index dfc41e2..f1658d3 100644
--- a/gdb/regformats/i386/amd64-avx512-linux.dat
+++ b/gdb/regformats/i386/amd64-avx512-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/amd64-linux.dat b/gdb/regformats/i386/amd64-linux.dat
index 6914cc4..cd16a15 100644
--- a/gdb/regformats/i386/amd64-linux.dat
+++ b/gdb/regformats/i386/amd64-linux.dat
@@ -61,3 +61,5 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
diff --git a/gdb/regformats/i386/amd64-mpx-linux.dat b/gdb/regformats/i386/amd64-mpx-linux.dat
index 523ae01..10487f6 100644
--- a/gdb/regformats/i386/amd64-mpx-linux.dat
+++ b/gdb/regformats/i386/amd64-mpx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:bnd0raw
 128:bnd1raw
 128:bnd2raw
diff --git a/gdb/regformats/i386/x32-avx-linux.dat b/gdb/regformats/i386/x32-avx-linux.dat
index a2b8d02..eb0e3953 100644
--- a/gdb/regformats/i386/x32-avx-linux.dat
+++ b/gdb/regformats/i386/x32-avx-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/x32-avx512-linux.dat b/gdb/regformats/i386/x32-avx512-linux.dat
index 0f5b2ce..0b7f73a 100644
--- a/gdb/regformats/i386/x32-avx512-linux.dat
+++ b/gdb/regformats/i386/x32-avx512-linux.dat
@@ -61,6 +61,8 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
 128:ymm0h
 128:ymm1h
 128:ymm2h
diff --git a/gdb/regformats/i386/x32-linux.dat b/gdb/regformats/i386/x32-linux.dat
index d976a25..eee378f 100644
--- a/gdb/regformats/i386/x32-linux.dat
+++ b/gdb/regformats/i386/x32-linux.dat
@@ -61,3 +61,5 @@ expedite:rbp,rsp,rip
 128:xmm15
 32:mxcsr
 64:orig_rax
+64:fs_base
+64:gs_base
diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.c b/gdb/testsuite/gdb.arch/amd64-gs_base.c
new file mode 100644
index 0000000..b177d57
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c
@@ -0,0 +1,33 @@
+/* Unwinder test program for fs_base and gs_base.
+
+   Copyright 2016 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+func (int a)
+{
+  return a * a;
+}
+
+int
+main (void)
+{
+  volatile int a;
+  a = 10;
+  a = func (a);
+  return a;
+}
diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
new file mode 100644
index 0000000..ccd6b87
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
@@ -0,0 +1,57 @@
+# Copyright 2016 Free Software Foundation, Inc.
+
+# This file is part of the GDB testsuite.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { ![istarget "x86_64-*linux*"] } then {
+    verbose "Skipping x86_64 fs_base and gs_base tests."
+    return
+}
+
+standard_testfile
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+	  executable { debug }] != "" } {
+    untested ${testfile}.exp
+    return -1
+}
+
+
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+runto func
+
+gdb_test "print /x \$fs_base" "= $hex" "print fs_base"
+gdb_test "print /x \$gs_base" "= $hex" "print gs_base"
+
+gdb_test "print \$fs_base = 2" "= 2" "set fs_base"
+gdb_test "print \$gs_base = 3" "= 3" "set gs_base"
+
+# Test the presence of fs_base and gs_base on the system
+# register group and values.
+#
+set ws "\[\t \]*"
+set info_reg_out [multi_line "info register sys" \
+          "fs_base${ws}0x2${ws}2"\
+          "gs_base${ws}0x3${ws}3"\
+          "orig_rax${ws}$hex${ws}\[-\]$decimal" ]
+
+gdb_test "info register sys" $info_reg_out\
+   "info registers fs_base and gs_base with value "
+
-- 
2.9.3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-03  9:47 ` [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
@ 2016-11-05 14:55   ` John Baldwin
  2016-11-07 14:40     ` Tedeschi, Walfred
  2016-11-10 12:36   ` Gary Benson
  2016-11-23 12:02   ` Pedro Alves
  2 siblings, 1 reply; 13+ messages in thread
From: John Baldwin @ 2016-11-05 14:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Walfred Tedeschi, palves, eliz, brobecker

On Thursday, November 03, 2016 10:47:25 AM Walfred Tedeschi wrote:
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 3f2a92b..a8a0b79 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -1872,6 +1881,18 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>      tdesc = tdesc_amd64_linux;
>    tdep->tdesc = tdesc;
>  
> +  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
> +  if (feature != NULL)
> +    {
> +      struct tdesc_arch_data *tdesc_data_segments
> +      = (struct tdesc_arch_data *) info.tdep_info;
> +
> +      tdesc_numbered_register (feature, tdesc_data_segments,
> +			       AMD64_FSBASE_REGNUM, "fs_base");
> +      tdesc_numbered_register (feature, tdesc_data_segments,
> +			       AMD64_GSBASE_REGNUM, "gs_base");
> +    }
> +
>    feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
>    if (feature == NULL)
>      return;

Should this be done in the OS-independent amd64_init_abi() instead?
FreeBSD also has ptrace operations to get/set the FS and GS base
registers (which I will add as a followup once this series is
committed).

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-05 14:55   ` John Baldwin
@ 2016-11-07 14:40     ` Tedeschi, Walfred
  0 siblings, 0 replies; 13+ messages in thread
From: Tedeschi, Walfred @ 2016-11-07 14:40 UTC (permalink / raw)
  To: John Baldwin, gdb-patches; +Cc: palves, eliz, brobecker

> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 
> 3f2a92b..a8a0b79 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -1872,6 +1881,18 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
>      tdesc = tdesc_amd64_linux;
>    tdep->tdesc = tdesc;
>  
> +  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");  
> + if (feature != NULL)
> +    {
> +      struct tdesc_arch_data *tdesc_data_segments
> +      = (struct tdesc_arch_data *) info.tdep_info;
> +
> +      tdesc_numbered_register (feature, tdesc_data_segments,
> +			       AMD64_FSBASE_REGNUM, "fs_base");
> +      tdesc_numbered_register (feature, tdesc_data_segments,
> +			       AMD64_GSBASE_REGNUM, "gs_base");
> +    }
> +
>    feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
>    if (feature == NULL)
>      return;

Should this be done in the OS-independent amd64_init_abi() instead?
FreeBSD also has ptrace operations to get/set the FS and GS base registers (which I will add as a followup once this series is committed).


John,

Thanks for the review! :)
I can place the code there. I also have to change fix a regression on a test on gcore.
Next review I do in the way you proposed. I can also place the changes in a dedicated branch if it helps.

Thanks and regards,
Fred
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-03  9:47 ` [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
  2016-11-05 14:55   ` John Baldwin
@ 2016-11-10 12:36   ` Gary Benson
  2016-11-30 13:31     ` Tedeschi, Walfred
  2016-11-23 12:02   ` Pedro Alves
  2 siblings, 1 reply; 13+ messages in thread
From: Gary Benson @ 2016-11-10 12:36 UTC (permalink / raw)
  To: Walfred Tedeschi; +Cc: palves, eliz, brobecker, gdb-patches

Walfred Tedeschi wrote:
> This patch allows examination of the registers FS_BASE and GS_BASE
> for Linux Systems running on 64bit. Tests for simple read and write
> of the new registers is also added with this patch.

I tried to add this support a while back and failed, so naturally I
think this is amazing--thank you for doing it!

> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 3f2a92b..a8a0b79 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
> +  /* System register added at the end.  */
> +#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
>  

What is the meaning of the comment?  And why did you add the new
fields before orig_rax?  I'm not disputing what you've done, I'd
just like to understand it.

I'm not a maintainer so can't approve this, but everything looks
right about it in terms of formatting, etc.

Thanks,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver.
  2016-11-03  9:47 ` [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver Walfred Tedeschi
@ 2016-11-10 12:37   ` Gary Benson
  2016-11-23 12:02     ` Pedro Alves
  0 siblings, 1 reply; 13+ messages in thread
From: Gary Benson @ 2016-11-10 12:37 UTC (permalink / raw)
  To: Walfred Tedeschi; +Cc: palves, eliz, brobecker, gdb-patches

Walfred Tedeschi wrote:
> diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
> index bbce742..376ca9d 100755
> --- a/gdb/gdbserver/configure
> +++ b/gdb/gdbserver/configure
> @@ -7591,6 +7591,32 @@ _ACEOF
>  fi
>  
>  
> +# See if <sys/user.h> supports the %fs_base and %gs_bas amd64 segment registers.
> +# Older amd64 Linux's don't have the fs_base and gs_base members of
> +# `struct user_regs_struct'.

I'd mildly prefer to see these comments wrapped at 72 columns, but
I know the rules are different in autoconf files so please don't
consider this a blocker.

Thanks,
Gary

-- 
http://gbenson.net/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-03  9:47 ` [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
  2016-11-05 14:55   ` John Baldwin
  2016-11-10 12:36   ` Gary Benson
@ 2016-11-23 12:02   ` Pedro Alves
  2016-11-30 10:29     ` Tedeschi, Walfred
  2 siblings, 1 reply; 13+ messages in thread
From: Pedro Alves @ 2016-11-23 12:02 UTC (permalink / raw)
  To: Walfred Tedeschi, eliz, brobecker; +Cc: gdb-patches

On 11/03/2016 09:47 AM, Walfred Tedeschi wrote:
> This patch allows examination of the registers FS_BASE and GS_BASE
> for Linux Systems running on 64bit. Tests for simple read and write
> of the new registers is also added with this patch.
> 
> Tests were performed on:
> x86_64 RHEL 5.3     - For the older ptrace calls.
> x86_64 Ubuntu 16.10 - For the new ptrace calls.
> 
> 2016-04-26  Walfred Tedeschi  <walfred.tedeschi@intel.com>
> 	    Richard Henderson  <rth@redhat.com>

What changed compared to Richard's original version?

>  \f
> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> index 3f2a92b..a8a0b79 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
> +  /* System register added at the end.  */
> +#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" */
> +

Spurious new line?

How's this meant to work for cross debugging, and core debugging?

I don't think it makes sense to put a host-specific
"#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE" check in a tdep file.

> diff --git a/gdb/features/Makefile b/gdb/features/Makefile
> index 30eed5d..c87f29f 100644
> --- a/gdb/features/Makefile
> +++ b/gdb/features/Makefile
> @@ -259,7 +259,7 @@ $(outdir)/i386/i386-linux.dat: i386/32bit-core.xml i386/32bit-sse.xml \
>  			       i386/32bit-linux.xml
>  $(outdir)/i386/amd64.dat: i386/64bit-core.xml i386/64bit-sse.xml
>  $(outdir)/i386/amd64-linux.dat: i386/64bit-core.xml i386/64bit-sse.xml \
> -			        i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>  $(outdir)/i386/i386-avx.dat: i386/32bit-core.xml i386/32bit-avx.xml
>  $(outdir)/i386/i386-avx-linux.dat: i386/32bit-core.xml i386/32bit-avx.xml \
>  			       i386/32bit-linux.xml
> @@ -279,11 +279,11 @@ $(outdir)/i386/i386-mmx.dat: i386/32bit-core.xml
>  $(outdir)/i386/i386-mmx-linux.dat: i386/32bit-core.xml i386/32bit-linux.xml
>  $(outdir)/i386/amd64-avx.dat: i386/64bit-core.xml i386/64bit-avx.xml
>  $(outdir)/i386/amd64-avx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
> -				    i386/64bit-linux.xml
> +			       i386/64bit-linux.xml i386/64bit-segments.xml

Is indentation on these two changes above correct?  Can't tell from
the mail client.

> +++ b/gdb/features/i386/64bit-segments.xml
> @@ -0,0 +1,12 @@
> +<?xml version="1.0"?>
> +<!-- Copyright (C) 2016 Free Software Foundation, Inc.
> +
> +     Copying and distribution of this file, with or without modification,
> +     are permitted in any medium without royalty provided the copyright
> +     notice and this notice are preserved.  -->
> +
> +<!DOCTYPE feature SYSTEM "gdb-target.dtd">
> +<feature name="org.gnu.gdb.i386.segments">
> +  <reg name="fs_base" bitsize="64" type="int" regnum="58"/>
> +  <reg name="gs_base" bitsize="64" type="int" regnum="59"/>

#1 - Why is "regnum" hard coded?

#2 - Is bitsize 64 and type "int" really correct?


> --- a/gdb/gdbserver/linux-x86-low.c
> +++ b/gdb/gdbserver/linux-x86-low.c
> @@ -133,6 +133,11 @@ static const int x86_64_regmap[] =
>    -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    ORIG_RAX * 8,
> +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +  21 * 8,  22 * 8,
> +#else
> +  -1, -1,
> +#endif
>    -1, -1, -1, -1,			/* MPX registers BND0 ... BND3.  */

It's curious that above this was put after orig_rax, while
here:

--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
   -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
   -1, -1, -1, -1, -1, -1, -1, -1,
+  /* System register added at the end.  */
+#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" */
+

It was put before.

> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c
> @@ -0,0 +1,33 @@
> +/* Unwinder test program for fs_base and gs_base.

What aspect of the unwinder is being tested?

> +
> +int
> +func (int a)
> +{
> +  return a * a;
> +}
> +
> +int
> +main (void)
> +{
> +  volatile int a;
> +  a = 10;
> +  a = func (a);

Is any of this relevant for the test?

> +  return a;
> +}
> diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
> new file mode 100644
> index 0000000..ccd6b87
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
> @@ -0,0 +1,57 @@
> +# Copyright 2016 Free Software Foundation, Inc.
> +
> +# This file is part of the GDB testsuite.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +if { ![istarget "x86_64-*linux*"] } then {
> +    verbose "Skipping x86_64 fs_base and gs_base tests."
> +    return
> +}
> +
> +standard_testfile
> +
> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
> +	  executable { debug }] != "" } {
> +    untested ${testfile}.exp
> +    return -1
> +}
> +
> +
> +
> +gdb_exit
> +gdb_start
> +gdb_reinitialize_dir $srcdir/$subdir
> +gdb_load ${binfile}
> +
> +runto func
> +

Use prepare_for_testing and handle runto failure.

> +gdb_test "info register sys" $info_reg_out\
> +   "info registers fs_base and gs_base with value "

Spurious space after "value".

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver.
  2016-11-10 12:37   ` Gary Benson
@ 2016-11-23 12:02     ` Pedro Alves
  0 siblings, 0 replies; 13+ messages in thread
From: Pedro Alves @ 2016-11-23 12:02 UTC (permalink / raw)
  To: Gary Benson, Walfred Tedeschi; +Cc: eliz, brobecker, gdb-patches

On 11/10/2016 12:37 PM, Gary Benson wrote:
> Walfred Tedeschi wrote:
>> diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
>> index bbce742..376ca9d 100755
>> --- a/gdb/gdbserver/configure
>> +++ b/gdb/gdbserver/configure
>> @@ -7591,6 +7591,32 @@ _ACEOF
>>  fi
>>  
>>  
>> +# See if <sys/user.h> supports the %fs_base and %gs_bas amd64 segment registers.
>> +# Older amd64 Linux's don't have the fs_base and gs_base members of
>> +# `struct user_regs_struct'.
> 
> I'd mildly prefer to see these comments wrapped at 72 columns, 

There's a typo "%gs_bas" in there.  It's present in gdb's configure.ac too,
where this was copied this from.  With the typo fixed, the line exceeds
80 columns, so the paragraph will need to be reflowed anyway. 

So OK with typo fixed and comment re-wrapped.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-23 12:02   ` Pedro Alves
@ 2016-11-30 10:29     ` Tedeschi, Walfred
  2016-12-07 16:37       ` Pedro Alves
  0 siblings, 1 reply; 13+ messages in thread
From: Tedeschi, Walfred @ 2016-11-30 10:29 UTC (permalink / raw)
  To: Pedro Alves, eliz, brobecker; +Cc: gdb-patches

On 11/23/2016 01:01 PM, Pedro Alves wrote:
> On 11/03/2016 09:47 AM, Walfred Tedeschi wrote:
>> This patch allows examination of the registers FS_BASE and GS_BASE
>> for Linux Systems running on 64bit. Tests for simple read and write
>> of the new registers is also added with this patch.
>>
>> Tests were performed on:
>> x86_64 RHEL 5.3     - For the older ptrace calls.
>> x86_64 Ubuntu 16.10 - For the new ptrace calls.
>>
>> 2016-04-26  Walfred Tedeschi  <walfred.tedeschi@intel.com>
>> 	    Richard Henderson  <rth@redhat.com>
> What changed compared to Richard's original version?
I have added a test, gdbserver support was also added by me.
>>   \f
>> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
>> index 3f2a92b..a8a0b79 100644
>> --- a/gdb/amd64-linux-tdep.c
>> +++ b/gdb/amd64-linux-tdep.c
>> @@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>> +  /* System register added at the end.  */
>> +#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" */
>> +
> Spurious new line?
Yes, fixed for the next version.
>
> How's this meant to work for cross debugging, and core debugging?
I have used the loopback board to test the remote scenario, but it can 
be that this is not enough.
You have just pointed out one problem with this setup.

Core debugging was working automatically, as far as i could see. Core 
testes passed and have reported the FS_base register and GS_base registers.
gcore tests report fs_base and gs_base registers while reading the 
registers from the core file.

For remote: I tested on loop back scenario, it also show good results.

Not sure if i have answered your questions.

> I don't think it makes sense to put a host-specific
> "#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE" check in a tdep file.
Agreed! I am using values that take into account the newest kernel.
On the other hand for older kernels there is the need to return -1 on 
the native file, like the snippet below:

diff --git a/gdb/amd64-nat.c b/gdb/amd64-nat.c
index ad5df57..e929735 100644
--- a/gdb/amd64-nat.c
+++ b/gdb/amd64-nat.c
@@ -65,6 +65,11 @@ amd64_native_gregset_reg_offset (struct gdbarch 
*gdbarch, int regnum)
    if (num_regs > gdbarch_num_regs (gdbarch))
      num_regs = gdbarch_num_regs (gdbarch);

+#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
+  if (regnum == AMD64_FSBASE_REGNUM || regnum == AMD64_GSBASE_REGNUM)
+    return -1;
+#endif

would this be ok?
>> diff --git a/gdb/features/Makefile b/gdb/features/Makefile
>> index 30eed5d..c87f29f 100644
>> --- a/gdb/features/Makefile
>> +++ b/gdb/features/Makefile
>> @@ -259,7 +259,7 @@ $(outdir)/i386/i386-linux.dat: i386/32bit-core.xml i386/32bit-sse.xml \
>>   			       i386/32bit-linux.xml
>>   $(outdir)/i386/amd64.dat: i386/64bit-core.xml i386/64bit-sse.xml
>>   $(outdir)/i386/amd64-linux.dat: i386/64bit-core.xml i386/64bit-sse.xml \
>> -			        i386/64bit-linux.xml
>> +			       i386/64bit-linux.xml i386/64bit-segments.xml
>>   $(outdir)/i386/i386-avx.dat: i386/32bit-core.xml i386/32bit-avx.xml
>>   $(outdir)/i386/i386-avx-linux.dat: i386/32bit-core.xml i386/32bit-avx.xml \
>>   			       i386/32bit-linux.xml
>> @@ -279,11 +279,11 @@ $(outdir)/i386/i386-mmx.dat: i386/32bit-core.xml
>>   $(outdir)/i386/i386-mmx-linux.dat: i386/32bit-core.xml i386/32bit-linux.xml
>>   $(outdir)/i386/amd64-avx.dat: i386/64bit-core.xml i386/64bit-avx.xml
>>   $(outdir)/i386/amd64-avx-linux.dat: i386/64bit-core.xml i386/64bit-avx.xml \
>> -				    i386/64bit-linux.xml
>> +			       i386/64bit-linux.xml i386/64bit-segments.xml
> Is indentation on these two changes above correct?  Can't tell from
> the mail client.
Yes, now all lines have same indentation.
>> +++ b/gdb/features/i386/64bit-segments.xml
>> @@ -0,0 +1,12 @@
>> +<?xml version="1.0"?>
>> +<!-- Copyright (C) 2016 Free Software Foundation, Inc.
>> +
>> +     Copying and distribution of this file, with or without modification,
>> +     are permitted in any medium without royalty provided the copyright
>> +     notice and this notice are preserved.  -->
>> +
>> +<!DOCTYPE feature SYSTEM "gdb-target.dtd">
>> +<feature name="org.gnu.gdb.i386.segments">
>> +  <reg name="fs_base" bitsize="64" type="int" regnum="58"/>
>> +  <reg name="gs_base" bitsize="64" type="int" regnum="59"/>
> #1 - Why is "regnum" hard coded?
Removed that, thanks.
>
> #2 - Is bitsize 64 and type "int" really correct?
I suppose you saw something wrong here, that i missed.
My reaoning was the following: I used for gs_base and fs_base the same 
type used for orig_rax as they also have the same type the user_reg_struct.
from sys/user.h:
struct user_regs_struct
{
   __extension__ unsigned long long int r15;
...
   __extension__ unsigned long long int orig_rax;
...
   __extension__ unsigned long long int fs_base;
   __extension__ unsigned long long int gs_base;

...
>
>
>> --- a/gdb/gdbserver/linux-x86-low.c
>> +++ b/gdb/gdbserver/linux-x86-low.c
>> @@ -133,6 +133,11 @@ static const int x86_64_regmap[] =
>>     -1,
>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>     ORIG_RAX * 8,
>> +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
>> +  21 * 8,  22 * 8,
>> +#else
>> +  -1, -1,
>> +#endif
>>     -1, -1, -1, -1,			/* MPX registers BND0 ... BND3.  */
> It's curious that above this was put after orig_rax, while
> here:

This is due to the fact that we usually let orig_rax at last.
In the gdb side we fix it by means of the macros.
However, we are adding new system register we could change that a bit now.
Would you consider that it would be better to keep the block of the 
system registers at last in the order they were introduced?

I.e. now we let the fs_base and gs_base at last instead of the orig_rax.

> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
>     -1, -1, -1, -1, -1, -1, -1, -1,
>     -1, -1, -1, -1, -1, -1, -1, -1,
>     -1, -1, -1, -1, -1, -1, -1, -1,
> +  /* System register added at the end.  */
> +#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" */
> +
>
> It was put before.
>
>> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.c
>> @@ -0,0 +1,33 @@
>> +/* Unwinder test program for fs_base and gs_base.
> What aspect of the unwinder is being tested?
Sorry, wrong message.
>
>> +
>> +int
>> +func (int a)
>> +{
>> +  return a * a;
>> +}
>> +
>> +int
>> +main (void)
>> +{
>> +  volatile int a;
>> +  a = 10;
>> +  a = func (a);
> Is any of this relevant for the test?
Not anymore. I did a previous version doing a step to force update of 
registers
in order to verify if the register written would survive.

This version was abandoned but code remained.
>> +  return a;
>> +}
>> diff --git a/gdb/testsuite/gdb.arch/amd64-gs_base.exp b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
>> new file mode 100644
>> index 0000000..ccd6b87
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.arch/amd64-gs_base.exp
>> @@ -0,0 +1,57 @@
>> +# Copyright 2016 Free Software Foundation, Inc.
>> +
>> +# This file is part of the GDB testsuite.
>> +
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 3 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +if { ![istarget "x86_64-*linux*"] } then {
>> +    verbose "Skipping x86_64 fs_base and gs_base tests."
>> +    return
>> +}
>> +
>> +standard_testfile
>> +
>> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
>> +	  executable { debug }] != "" } {
>> +    untested ${testfile}.exp
>> +    return -1
>> +}
>> +
>> +
>> +
>> +gdb_exit
>> +gdb_start
>> +gdb_reinitialize_dir $srcdir/$subdir
>> +gdb_load ${binfile}
>> +
>> +runto func
>> +
> Use prepare_for_testing and handle runto failure.
fixed for the next version.
>
>> +gdb_test "info register sys" $info_reg_out\
>> +   "info registers fs_base and gs_base with value "
> Spurious space after "value".
yes, fixed for the next version.
>
> Thanks,
> Pedro Alves
>


Thanks a lot for your review!

Best regards,
/Fred
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-10 12:36   ` Gary Benson
@ 2016-11-30 13:31     ` Tedeschi, Walfred
  0 siblings, 0 replies; 13+ messages in thread
From: Tedeschi, Walfred @ 2016-11-30 13:31 UTC (permalink / raw)
  To: Gary Benson; +Cc: palves, eliz, brobecker, gdb-patches



-----Original Message-----
From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Gary Benson
Sent: Thursday, November 10, 2016 12:36 PM
To: Tedeschi, Walfred <walfred.tedeschi@intel.com>
Cc: palves@redhat.com; eliz@gnu.org; brobecker@adacore.com; gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.

Walfred Tedeschi wrote:
> This patch allows examination of the registers FS_BASE and GS_BASE for 
> Linux Systems running on 64bit. Tests for simple read and write of the 
> new registers is also added with this patch.

I tried to add this support a while back and failed, so naturally I think this is amazing--thank you for doing it!

> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 
> 3f2a92b..a8a0b79 100644
> --- a/gdb/amd64-linux-tdep.c
> +++ b/gdb/amd64-linux-tdep.c
> @@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
>    -1, -1, -1, -1, -1, -1, -1, -1,
> +  /* System register added at the end.  */ #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" */
> +
>  };
>  

>  

What is the meaning of the comment?  And why did you add the new fields before orig_rax?  I'm not disputing what you've done, I'd just like to understand it.

I'm not a maintainer so can't approve this, but everything looks right about it in terms of formatting, etc.

Thanks,
Gary


Gary,

Thanks for your review! Usually the orig_rax was left as last register, i have tried to follow that.
On the other hand, since we are adding new szstem registers there is no reason to keep specifically orig_rax at the end.

I will move them around. 

Thanks again,
/Fred
--
http://gbenson.net/
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/2] amd64: add fs_base and gs_base
  2016-11-03  9:47 [PATCH 0/2] amd64: add fs_base and gs_base Walfred Tedeschi
  2016-11-03  9:47 ` [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver Walfred Tedeschi
  2016-11-03  9:47 ` [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
@ 2016-11-30 14:20 ` Gary Benson
  2 siblings, 0 replies; 13+ messages in thread
From: Gary Benson @ 2016-11-30 14:20 UTC (permalink / raw)
  To: Walfred Tedeschi; +Cc: palves, eliz, brobecker, gdb-patches

Hi Walfred,

Walfred Tedeschi wrote:
> The next two patches add Linux system registers fs_base and gs_base
> in GDB and gdbserver.
> 
> First commit align the gdbserver with GDB code  in terms of
> HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE.
> 
> Second patch introduces the registers into GDB and gdbserver.

I tried this with the Infinity stuff I'm doing today and it's working
great.  The only change I had to make was to add the new registers to
amd64_dwarf_regmap with the patch below.

Thanks,
Gary

-- 
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index a3a1fde..d0450cc 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -223,8 +223,8 @@ static int amd64_dwarf_regmap[] =
   -1,
 
   /* Segment Base Address Registers.  */
-  -1,
-  -1,
+  AMD64_FSBASE_REGNUM,
+  AMD64_GSBASE_REGNUM,
   -1,
   -1,
 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
  2016-11-30 10:29     ` Tedeschi, Walfred
@ 2016-12-07 16:37       ` Pedro Alves
  0 siblings, 0 replies; 13+ messages in thread
From: Pedro Alves @ 2016-12-07 16:37 UTC (permalink / raw)
  To: Tedeschi, Walfred, eliz, brobecker; +Cc: gdb-patches

On 11/30/2016 10:29 AM, Tedeschi, Walfred wrote:
> On 11/23/2016 01:01 PM, Pedro Alves wrote:
>> On 11/03/2016 09:47 AM, Walfred Tedeschi wrote:
>>> This patch allows examination of the registers FS_BASE and GS_BASE
>>> for Linux Systems running on 64bit. Tests for simple read and write
>>> of the new registers is also added with this patch.
>>>
>>> Tests were performed on:
>>> x86_64 RHEL 5.3     - For the older ptrace calls.
>>> x86_64 Ubuntu 16.10 - For the new ptrace calls.
>>>
>>> 2016-04-26  Walfred Tedeschi  <walfred.tedeschi@intel.com>
>>>         Richard Henderson  <rth@redhat.com>
>> What changed compared to Richard's original version?
> I have added a test, gdbserver support was also added by me.
>>>   \f
>>> diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
>>> index 3f2a92b..a8a0b79 100644
>>> --- a/gdb/amd64-linux-tdep.c
>>> +++ b/gdb/amd64-linux-tdep.c
>>> @@ -103,7 +103,14 @@ int amd64_linux_gregset_reg_offset[] =
>>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>> +  /* System register added at the end.  */
>>> +#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" */
>>> +
>> Spurious new line?
> Yes, fixed for the next version.
>>
>> How's this meant to work for cross debugging, and core debugging?
> I have used the loopback board to test the remote scenario, but it can
> be that this is not enough.

Right, that doesn't really exercise cross debugging, because in that
case, both gdb and gdbserver are running on the same architecture.

> You have just pointed out one problem with this setup.
> 
> Core debugging was working automatically, as far as i could see. Core
> testes passed and have reported the FS_base register and GS_base registers.
> gcore tests report fs_base and gs_base registers while reading the
> registers from the core file.

That's another manifestation of the same testing environment
issue -- what if you load the x86 core on an ARM host?  Then
HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE won't be defined, while
the data is available.  Also what happens if you load a core
dump generated on an old kernel, into a gdb running/built on
a new kernel.  And likewise the other way around (dump on new
kernel, load on gdb built on old kernel).  This is the sort
of host-independence concerns that the core reading code
should be having.

> 
> For remote: I tested on loop back scenario, it also show good results.
> 
> Not sure if i have answered your questions.

Not exactly.

> 
>> I don't think it makes sense to put a host-specific
>> "#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE" check in a tdep file.
> Agreed! I am using values that take into account the newest kernel.
> On the other hand for older kernels there is the need to return -1 on
> the native file, like the snippet below:

See above.

> 
> diff --git a/gdb/amd64-nat.c b/gdb/amd64-nat.c
> index ad5df57..e929735 100644
> --- a/gdb/amd64-nat.c
> +++ b/gdb/amd64-nat.c
> @@ -65,6 +65,11 @@ amd64_native_gregset_reg_offset (struct gdbarch
> *gdbarch, int regnum)
>    if (num_regs > gdbarch_num_regs (gdbarch))
>      num_regs = gdbarch_num_regs (gdbarch);
> 
> +#ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
> +  if (regnum == AMD64_FSBASE_REGNUM || regnum == AMD64_GSBASE_REGNUM)
> +    return -1;
> +#endif
> 
> would this be ok?

I don't know exactly what this change means.
Is HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE really about kernel
version, or libc version?  E.g., what do older kernels put
in those gregset offsets?

>>> +++ b/gdb/features/i386/64bit-segments.xml
>>> @@ -0,0 +1,12 @@
>>> +<?xml version="1.0"?>
>>> +<!-- Copyright (C) 2016 Free Software Foundation, Inc.
>>> +
>>> +     Copying and distribution of this file, with or without
>>> modification,
>>> +     are permitted in any medium without royalty provided the copyright
>>> +     notice and this notice are preserved.  -->
>>> +
>>> +<!DOCTYPE feature SYSTEM "gdb-target.dtd">
>>> +<feature name="org.gnu.gdb.i386.segments">
>>> +  <reg name="fs_base" bitsize="64" type="int" regnum="58"/>
>>> +  <reg name="gs_base" bitsize="64" type="int" regnum="59"/>
>> #1 - Why is "regnum" hard coded?
> Removed that, thanks.
>>
>> #2 - Is bitsize 64 and type "int" really correct?
> I suppose you saw something wrong here, that i missed.

Well, I'm seeing "int" and thinking "32-bit", since that's what
it usually is, but then we have bitsize 64-bit.

> My reaoning was the following: I used for gs_base and fs_base the same
> type used for orig_rax as they also have the same type the user_reg_struct.

Funny, that's the only other case like this:

$ grep -rn "type=\"int\"" | grep \"64\"
i386/64bit-linux.xml:10:  <reg name="orig_rax" bitsize="64" type="int" regnum="57"/>

Looks like gdb may be being smart about this:

 (gdb) ptype $orig_rax
 type = long

Is that the type you get back for the new registers too?

>>> --- a/gdb/gdbserver/linux-x86-low.c
>>> +++ b/gdb/gdbserver/linux-x86-low.c
>>> @@ -133,6 +133,11 @@ static const int x86_64_regmap[] =
>>>     -1,
>>>     -1, -1, -1, -1, -1, -1, -1, -1,
>>>     ORIG_RAX * 8,
>>> +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
>>> +  21 * 8,  22 * 8,
>>> +#else
>>> +  -1, -1,
>>> +#endif
>>>     -1, -1, -1, -1,            /* MPX registers BND0 ... BND3.  */
>> It's curious that above this was put after orig_rax, while
>> here:
> 
> This is due to the fact that we usually let orig_rax at last.
> In the gdb side we fix it by means of the macros.

I'm afraid you lost me.  What macros?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-12-07 16:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-03  9:47 [PATCH 0/2] amd64: add fs_base and gs_base Walfred Tedeschi
2016-11-03  9:47 ` [PATCH 1/2] gdbserver-amd64: add HAVE_STRUCT_USER_REGS_STRUCT_(GS|FS)_BASE for gdbserver Walfred Tedeschi
2016-11-10 12:37   ` Gary Benson
2016-11-23 12:02     ` Pedro Alves
2016-11-03  9:47 ` [PATCH 2/2] amd64-linux: expose system register FS_BASE and GS_BASE for Linux Walfred Tedeschi
2016-11-05 14:55   ` John Baldwin
2016-11-07 14:40     ` Tedeschi, Walfred
2016-11-10 12:36   ` Gary Benson
2016-11-30 13:31     ` Tedeschi, Walfred
2016-11-23 12:02   ` Pedro Alves
2016-11-30 10:29     ` Tedeschi, Walfred
2016-12-07 16:37       ` Pedro Alves
2016-11-30 14:20 ` [PATCH 0/2] amd64: add fs_base and gs_base Gary Benson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).