From 3e7fa952aa12f56bafe02e0dab47eb9c690e9f47 Mon Sep 17 00:00:00 2001 From: Markus Metzger Date: Fri, 22 Nov 2019 16:55:14 +0100 Subject: [PATCH] x86: support fs_base and gs_base for 32-bit inferiors on 64-bit kernels On Linux 64-bit kernels provide fs_base and gs_base also for 32-bit inferiors. Add support for those registers. Also check for HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE consistently. Signed-off-by: Markus Metzger gdb/ * amd64-linux-nat.c (amd64_linux_gregset32_reg_offset): Add FS_BASE and GS_BASE offsets. * amd64-linux-tdep.c (amd64_linux_gregset_reg_offset): Check HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE. (amd64_linux_read_description): Enable segments if HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE. * i386-linux-tdep.c (i386_linux_gregset_reg_offset): Add -1 for FS_BASE and GS_BASE offsets. (i386_linux_read_description): Enable segments if HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE. * i386-linux-tdep.h (I386_LINUX_ORIG_EAX_REGNUM): Update. Change-Id: I030b500a7a5b087452a78c3e0545d6e6e65146aa --- gdb/amd64-linux-nat.c | 5 +++++ gdb/amd64-linux-tdep.c | 12 +++++++++++- gdb/i386-linux-tdep.c | 9 ++++++++- gdb/i386-linux-tdep.h | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c index d0328b677d5..ce2e980ad4e 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -85,6 +85,11 @@ static int amd64_linux_gregset32_reg_offset[] = -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */ -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */ -1, /* PKEYS register PKRU */ +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE + FS_BASE * 8, GS_BASE * 8, /* fs_base and gs_base */ +#else + -1, -1, /* fs_base and gs_base */ +#endif ORIG_RAX * 8 /* "orig_eax" */ }; diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c index 7ec08c7fc49..918dbed617c 100644 --- a/gdb/amd64-linux-tdep.c +++ b/gdb/amd64-linux-tdep.c @@ -98,7 +98,11 @@ int amd64_linux_gregset_reg_offset[] = -1, /* PKEYS register pkru */ /* End of hardware registers */ +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE 21 * 8, 22 * 8, /* fs_base and gs_base. */ +#else + -1, -1, /* fs_base and gs_base. */ +#endif 15 * 8 /* "orig_rax" */ }; @@ -1593,9 +1597,15 @@ amd64_linux_read_description (uint64_t xcr0_features_bit, bool is_x32) [(xcr0_features_bit & X86_XSTATE_PKRU) ? 1 : 0]; } +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE + const bool segment = true; +#else + const bool segment = false; +#endif + if (*tdesc == NULL) *tdesc = amd64_create_target_description (xcr0_features_bit, is_x32, - true, true); + true, segment); return *tdesc; } diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 0f10686bc01..9cb2cd16e55 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -609,6 +609,7 @@ int i386_linux_gregset_reg_offset[] = -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */ -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */ -1, /* PKRU register */ + -1, -1, /* fs_base and gs_base. */ 11 * 4, /* "orig_eax" */ }; @@ -692,8 +693,14 @@ i386_linux_read_description (uint64_t xcr0) [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0] [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]; +#ifdef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE + const bool segment = true; +#else + const bool segment = false; +#endif + if (*tdesc == NULL) - *tdesc = i386_create_target_description (xcr0, true, false); + *tdesc = i386_create_target_description (xcr0, true, segment); return *tdesc; } diff --git a/gdb/i386-linux-tdep.h b/gdb/i386-linux-tdep.h index 4842d216244..6b048c5ad44 100644 --- a/gdb/i386-linux-tdep.h +++ b/gdb/i386-linux-tdep.h @@ -29,7 +29,7 @@ /* Register number for the "orig_eax" pseudo-register. If this pseudo-register contains a value >= 0 it is interpreted as the system call number that the kernel is supposed to restart. */ -#define I386_LINUX_ORIG_EAX_REGNUM (I386_PKRU_REGNUM + 1) +#define I386_LINUX_ORIG_EAX_REGNUM (I386_GSBASE_REGNUM + 1) /* Total number of registers for GNU/Linux. */ #define I386_LINUX_NUM_REGS (I386_LINUX_ORIG_EAX_REGNUM + 1) -- 2.47.2