forked from Imagelibrary/binutils-gdb
amd64-linux: expose system register FS_BASE and GS_BASE for Linux.
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. 2017-01-27 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-nat.c (amd64_native_gregset_reg_offset): Implements case for older kernels. * amd64-tdep.c (amd64_init_abi): Add segment registers for the amd64 ABI. * amd64-tdep.h (amd64_regnum): Add AMD64_FSBASE_REGNUM and AMD64_GSBASE_REGNUM. (AMD64_NUM_REGS): Set to AMD64_GSBASE_REGNUM + 1. * 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. * regformats/i386/amd64-avx-linux.dat: Regenerated. * regformats/i386/amd64-avx-mpx-linux.dat: Regenerated. * regformats/i386/amd64-avx512-linux.dat: Regenerated. * regformats/i386/amd64-linux.dat: Regenerated. * regformats/i386/amd64-mpx-linux.dat: Regenerated. * regformats/i386/x32-avx-linux.dat: Regenerated. * regformats/i386/x32-avx512-linux.dat: Regenerated. * regformats/i386/x32-linux.dat: 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. * configure.srv (srv_i386_64bit_xmlfiles): Add 64bit-segments.xml. gdb/testsuite/ChangeLog: * gdb.arch/amd64-gs_base.c: New file. * gdb.arch/amd64-gs_base.exp: New file. Change-Id: I2e0eeb93058a2320d4d3b045082643cfe4aff963 Signed-off-by: Walfred Tedeschi <walfred.tedeschi@intel.com>
This commit is contained in:
@@ -40,6 +40,12 @@
|
||||
#include "nat/linux-ptrace.h"
|
||||
#include "nat/amd64-linux-siginfo.h"
|
||||
|
||||
/* This definition comes from prctl.h. Kernels older than 2.5.64
|
||||
do 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 +177,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 +267,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 segment register 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 segment register gs_base"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,11 +319,7 @@ ps_get_thread_area (struct ps_prochandle *ph,
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This definition comes from prctl.h, but some kernels may not
|
||||
have it. */
|
||||
#ifndef PTRACE_ARCH_PRCTL
|
||||
#define PTRACE_ARCH_PRCTL 30
|
||||
#endif
|
||||
|
||||
/* FIXME: ezannoni-2003-07-09 see comment above about include
|
||||
file order. We could be getting bogus values for these two. */
|
||||
gdb_assert (FS < ELF_NGREG);
|
||||
|
||||
Reference in New Issue
Block a user