mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
0747795c08
This changes all includes to use the form "common/filename.h" rather than just "filename.h". This was written by a script. gdb/ChangeLog 2019-01-25 Tom Tromey <tom@tromey.com> * xtensa-linux-nat.c: Fix common/ includes. * xml-support.h: Fix common/ includes. * xml-support.c: Fix common/ includes. * x86-linux-nat.c: Fix common/ includes. * windows-nat.c: Fix common/ includes. * varobj.h: Fix common/ includes. * varobj.c: Fix common/ includes. * value.c: Fix common/ includes. * valops.c: Fix common/ includes. * utils.c: Fix common/ includes. * unittests/xml-utils-selftests.c: Fix common/ includes. * unittests/utils-selftests.c: Fix common/ includes. * unittests/unpack-selftests.c: Fix common/ includes. * unittests/tracepoint-selftests.c: Fix common/ includes. * unittests/style-selftests.c: Fix common/ includes. * unittests/string_view-selftests.c: Fix common/ includes. * unittests/scoped_restore-selftests.c: Fix common/ includes. * unittests/scoped_mmap-selftests.c: Fix common/ includes. * unittests/scoped_fd-selftests.c: Fix common/ includes. * unittests/rsp-low-selftests.c: Fix common/ includes. * unittests/parse-connection-spec-selftests.c: Fix common/ includes. * unittests/optional-selftests.c: Fix common/ includes. * unittests/offset-type-selftests.c: Fix common/ includes. * unittests/observable-selftests.c: Fix common/ includes. * unittests/mkdir-recursive-selftests.c: Fix common/ includes. * unittests/memrange-selftests.c: Fix common/ includes. * unittests/memory-map-selftests.c: Fix common/ includes. * unittests/lookup_name_info-selftests.c: Fix common/ includes. * unittests/function-view-selftests.c: Fix common/ includes. * unittests/environ-selftests.c: Fix common/ includes. * unittests/copy_bitwise-selftests.c: Fix common/ includes. * unittests/common-utils-selftests.c: Fix common/ includes. * unittests/cli-utils-selftests.c: Fix common/ includes. * unittests/array-view-selftests.c: Fix common/ includes. * ui-file.c: Fix common/ includes. * tui/tui-io.c: Fix common/ includes. * tracepoint.h: Fix common/ includes. * tracepoint.c: Fix common/ includes. * tracefile-tfile.c: Fix common/ includes. * top.h: Fix common/ includes. * top.c: Fix common/ includes. * thread.c: Fix common/ includes. * target/waitstatus.h: Fix common/ includes. * target/waitstatus.c: Fix common/ includes. * target.h: Fix common/ includes. * target.c: Fix common/ includes. * target-memory.c: Fix common/ includes. * target-descriptions.c: Fix common/ includes. * symtab.h: Fix common/ includes. * symfile.c: Fix common/ includes. * stap-probe.c: Fix common/ includes. * spu-linux-nat.c: Fix common/ includes. * sparc-nat.c: Fix common/ includes. * source.c: Fix common/ includes. * solib.c: Fix common/ includes. * solib-target.c: Fix common/ includes. * ser-unix.c: Fix common/ includes. * ser-tcp.c: Fix common/ includes. * ser-pipe.c: Fix common/ includes. * ser-base.c: Fix common/ includes. * selftest-arch.c: Fix common/ includes. * s12z-tdep.c: Fix common/ includes. * rust-exp.y: Fix common/ includes. * rs6000-aix-tdep.c: Fix common/ includes. * riscv-tdep.c: Fix common/ includes. * remote.c: Fix common/ includes. * remote-notif.h: Fix common/ includes. * remote-fileio.h: Fix common/ includes. * remote-fileio.c: Fix common/ includes. * regcache.h: Fix common/ includes. * regcache.c: Fix common/ includes. * record-btrace.c: Fix common/ includes. * python/python.c: Fix common/ includes. * python/py-type.c: Fix common/ includes. * python/py-inferior.c: Fix common/ includes. * progspace.h: Fix common/ includes. * producer.c: Fix common/ includes. * procfs.c: Fix common/ includes. * proc-api.c: Fix common/ includes. * printcmd.c: Fix common/ includes. * ppc-linux-nat.c: Fix common/ includes. * parser-defs.h: Fix common/ includes. * osdata.c: Fix common/ includes. * obsd-nat.c: Fix common/ includes. * nat/x86-linux.c: Fix common/ includes. * nat/x86-linux-dregs.c: Fix common/ includes. * nat/x86-dregs.h: Fix common/ includes. * nat/x86-dregs.c: Fix common/ includes. * nat/ppc-linux.c: Fix common/ includes. * nat/mips-linux-watch.h: Fix common/ includes. * nat/mips-linux-watch.c: Fix common/ includes. * nat/linux-waitpid.c: Fix common/ includes. * nat/linux-ptrace.h: Fix common/ includes. * nat/linux-ptrace.c: Fix common/ includes. * nat/linux-procfs.c: Fix common/ includes. * nat/linux-personality.c: Fix common/ includes. * nat/linux-osdata.c: Fix common/ includes. * nat/linux-namespaces.c: Fix common/ includes. * nat/linux-btrace.h: Fix common/ includes. * nat/linux-btrace.c: Fix common/ includes. * nat/fork-inferior.c: Fix common/ includes. * nat/amd64-linux-siginfo.c: Fix common/ includes. * nat/aarch64-sve-linux-ptrace.c: Fix common/ includes. * nat/aarch64-linux.c: Fix common/ includes. * nat/aarch64-linux-hw-point.h: Fix common/ includes. * nat/aarch64-linux-hw-point.c: Fix common/ includes. * namespace.h: Fix common/ includes. * mips-linux-tdep.c: Fix common/ includes. * minsyms.c: Fix common/ includes. * mi/mi-parse.h: Fix common/ includes. * mi/mi-main.c: Fix common/ includes. * mi/mi-cmd-env.c: Fix common/ includes. * memrange.h: Fix common/ includes. * memattr.c: Fix common/ includes. * maint.h: Fix common/ includes. * maint.c: Fix common/ includes. * main.c: Fix common/ includes. * machoread.c: Fix common/ includes. * location.c: Fix common/ includes. * linux-thread-db.c: Fix common/ includes. * linux-nat.c: Fix common/ includes. * linux-fork.c: Fix common/ includes. * inline-frame.c: Fix common/ includes. * infrun.c: Fix common/ includes. * inflow.c: Fix common/ includes. * inferior.h: Fix common/ includes. * inferior.c: Fix common/ includes. * infcmd.c: Fix common/ includes. * inf-ptrace.c: Fix common/ includes. * inf-child.c: Fix common/ includes. * ia64-linux-nat.c: Fix common/ includes. * i387-tdep.c: Fix common/ includes. * i386-tdep.c: Fix common/ includes. * i386-linux-tdep.c: Fix common/ includes. * i386-linux-nat.c: Fix common/ includes. * i386-go32-tdep.c: Fix common/ includes. * i386-fbsd-tdep.c: Fix common/ includes. * i386-fbsd-nat.c: Fix common/ includes. * guile/scm-type.c: Fix common/ includes. * guile/guile.c: Fix common/ includes. * go32-nat.c: Fix common/ includes. * gnu-nat.c: Fix common/ includes. * gdbthread.h: Fix common/ includes. * gdbarch-selftests.c: Fix common/ includes. * gdb_usleep.c: Fix common/ includes. * gdb_select.h: Fix common/ includes. * gdb_bfd.c: Fix common/ includes. * gcore.c: Fix common/ includes. * fork-child.c: Fix common/ includes. * findvar.c: Fix common/ includes. * fbsd-nat.c: Fix common/ includes. * event-top.c: Fix common/ includes. * event-loop.c: Fix common/ includes. * dwarf2read.c: Fix common/ includes. * dwarf2loc.c: Fix common/ includes. * dwarf2-frame.c: Fix common/ includes. * dwarf-index-cache.c: Fix common/ includes. * dtrace-probe.c: Fix common/ includes. * disasm-selftests.c: Fix common/ includes. * defs.h: Fix common/ includes. * csky-tdep.c: Fix common/ includes. * cp-valprint.c: Fix common/ includes. * cp-support.h: Fix common/ includes. * cp-support.c: Fix common/ includes. * corelow.c: Fix common/ includes. * completer.h: Fix common/ includes. * completer.c: Fix common/ includes. * compile/compile.c: Fix common/ includes. * compile/compile-loc2c.c: Fix common/ includes. * compile/compile-cplus-types.c: Fix common/ includes. * compile/compile-cplus-symbols.c: Fix common/ includes. * command.h: Fix common/ includes. * cli/cli-dump.c: Fix common/ includes. * cli/cli-cmds.c: Fix common/ includes. * charset.c: Fix common/ includes. * build-id.c: Fix common/ includes. * btrace.h: Fix common/ includes. * btrace.c: Fix common/ includes. * breakpoint.h: Fix common/ includes. * breakpoint.c: Fix common/ includes. * ax.h: (enum agent_op): Fix common/ includes. * ax-general.c (struct aop_map): Fix common/ includes. * ax-gdb.c: Fix common/ includes. * auxv.c: Fix common/ includes. * auto-load.c: Fix common/ includes. * arm-tdep.c: Fix common/ includes. * arch/riscv.c: Fix common/ includes. * arch/ppc-linux-common.c: Fix common/ includes. * arch/i386.c: Fix common/ includes. * arch/arm.c: Fix common/ includes. * arch/arm-linux.c: Fix common/ includes. * arch/arm-get-next-pcs.c: Fix common/ includes. * arch/amd64.c: Fix common/ includes. * arch/aarch64.c: Fix common/ includes. * arch/aarch64-insn.c: Fix common/ includes. * arch-utils.c: Fix common/ includes. * amd64-windows-tdep.c: Fix common/ includes. * amd64-tdep.c: Fix common/ includes. * amd64-sol2-tdep.c: Fix common/ includes. * amd64-obsd-tdep.c: Fix common/ includes. * amd64-nbsd-tdep.c: Fix common/ includes. * amd64-linux-tdep.c: Fix common/ includes. * amd64-linux-nat.c: Fix common/ includes. * amd64-fbsd-tdep.c: Fix common/ includes. * amd64-fbsd-nat.c: Fix common/ includes. * amd64-dicos-tdep.c: Fix common/ includes. * amd64-darwin-tdep.c: Fix common/ includes. * agent.c: Fix common/ includes. * ada-lang.h: Fix common/ includes. * ada-lang.c: Fix common/ includes. * aarch64-tdep.c: Fix common/ includes. gdb/gdbserver/ChangeLog 2019-01-25 Tom Tromey <tom@tromey.com> * win32-low.c: Fix common/ includes. * win32-i386-low.c: Fix common/ includes. * tracepoint.c: Fix common/ includes. * thread-db.c: Fix common/ includes. * target.h: Fix common/ includes. * symbol.c: Fix common/ includes. * spu-low.c: Fix common/ includes. * server.h: Fix common/ includes. * server.c: Fix common/ includes. * remote-utils.c: Fix common/ includes. * regcache.h: Fix common/ includes. * regcache.c: Fix common/ includes. * nto-x86-low.c: Fix common/ includes. * notif.h: Fix common/ includes. * mem-break.h: Fix common/ includes. * lynx-low.c: Fix common/ includes. * lynx-i386-low.c: Fix common/ includes. * linux-x86-tdesc-selftest.c: Fix common/ includes. * linux-x86-low.c: Fix common/ includes. * linux-low.c: Fix common/ includes. * inferiors.h: Fix common/ includes. * i387-fp.c: Fix common/ includes. * hostio.c: Fix common/ includes. * hostio-errno.c: Fix common/ includes. * gdbthread.h: Fix common/ includes. * gdbreplay.c: Fix common/ includes. * fork-child.c: Fix common/ includes. * event-loop.c: Fix common/ includes. * ax.c: (enum gdb_agent_op): Fix common/ includes.
426 lines
12 KiB
C
426 lines
12 KiB
C
/* Native-dependent code for GNU/Linux x86-64.
|
||
|
||
Copyright (C) 2001-2019 Free Software Foundation, Inc.
|
||
Contributed by Jiri Smid, SuSE Labs.
|
||
|
||
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/>. */
|
||
|
||
#include "defs.h"
|
||
#include "inferior.h"
|
||
#include "regcache.h"
|
||
#include "elf/common.h"
|
||
#include <sys/uio.h>
|
||
#include "nat/gdb_ptrace.h"
|
||
#include <asm/prctl.h>
|
||
#include <sys/reg.h>
|
||
#include "gregset.h"
|
||
#include "gdb_proc_service.h"
|
||
|
||
#include "amd64-nat.h"
|
||
#include "amd64-tdep.h"
|
||
#include "amd64-linux-tdep.h"
|
||
#include "i386-linux-tdep.h"
|
||
#include "common/x86-xstate.h"
|
||
|
||
#include "x86-linux-nat.h"
|
||
#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
|
||
|
||
struct amd64_linux_nat_target final : public x86_linux_nat_target
|
||
{
|
||
/* Add our register access methods. */
|
||
void fetch_registers (struct regcache *, int) override;
|
||
void store_registers (struct regcache *, int) override;
|
||
|
||
bool low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction)
|
||
override;
|
||
};
|
||
|
||
static amd64_linux_nat_target the_amd64_linux_nat_target;
|
||
|
||
/* Mapping between the general-purpose registers in GNU/Linux x86-64
|
||
`struct user' format and GDB's register cache layout for GNU/Linux
|
||
i386.
|
||
|
||
Note that most GNU/Linux x86-64 registers are 64-bit, while the
|
||
GNU/Linux i386 registers are all 32-bit, but since we're
|
||
little-endian we get away with that. */
|
||
|
||
/* From <sys/reg.h> on GNU/Linux i386. */
|
||
static int amd64_linux_gregset32_reg_offset[] =
|
||
{
|
||
RAX * 8, RCX * 8, /* %eax, %ecx */
|
||
RDX * 8, RBX * 8, /* %edx, %ebx */
|
||
RSP * 8, RBP * 8, /* %esp, %ebp */
|
||
RSI * 8, RDI * 8, /* %esi, %edi */
|
||
RIP * 8, EFLAGS * 8, /* %eip, %eflags */
|
||
CS * 8, SS * 8, /* %cs, %ss */
|
||
DS * 8, ES * 8, /* %ds, %es */
|
||
FS * 8, GS * 8, /* %fs, %gs */
|
||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||
-1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||
-1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
|
||
-1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
|
||
-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 */
|
||
ORIG_RAX * 8 /* "orig_eax" */
|
||
};
|
||
|
||
|
||
/* Transfering the general-purpose registers between GDB, inferiors
|
||
and core files. */
|
||
|
||
/* Fill GDB's register cache with the general-purpose register values
|
||
in *GREGSETP. */
|
||
|
||
void
|
||
supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
|
||
{
|
||
amd64_supply_native_gregset (regcache, gregsetp, -1);
|
||
}
|
||
|
||
/* Fill register REGNUM (if it is a general-purpose register) in
|
||
*GREGSETP with the value in GDB's register cache. If REGNUM is -1,
|
||
do this for all registers. */
|
||
|
||
void
|
||
fill_gregset (const struct regcache *regcache,
|
||
elf_gregset_t *gregsetp, int regnum)
|
||
{
|
||
amd64_collect_native_gregset (regcache, gregsetp, regnum);
|
||
}
|
||
|
||
/* Transfering floating-point registers between GDB, inferiors and cores. */
|
||
|
||
/* Fill GDB's register cache with the floating-point and SSE register
|
||
values in *FPREGSETP. */
|
||
|
||
void
|
||
supply_fpregset (struct regcache *regcache, const elf_fpregset_t *fpregsetp)
|
||
{
|
||
amd64_supply_fxsave (regcache, -1, fpregsetp);
|
||
}
|
||
|
||
/* Fill register REGNUM (if it is a floating-point or SSE register) in
|
||
*FPREGSETP with the value in GDB's register cache. If REGNUM is
|
||
-1, do this for all registers. */
|
||
|
||
void
|
||
fill_fpregset (const struct regcache *regcache,
|
||
elf_fpregset_t *fpregsetp, int regnum)
|
||
{
|
||
amd64_collect_fxsave (regcache, regnum, fpregsetp);
|
||
}
|
||
|
||
|
||
/* Transferring arbitrary registers between GDB and inferior. */
|
||
|
||
/* Fetch register REGNUM from the child process. If REGNUM is -1, do
|
||
this for all registers (including the floating point and SSE
|
||
registers). */
|
||
|
||
void
|
||
amd64_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum)
|
||
{
|
||
struct gdbarch *gdbarch = regcache->arch ();
|
||
int tid;
|
||
|
||
/* GNU/Linux LWP ID's are process ID's. */
|
||
tid = regcache->ptid ().lwp ();
|
||
if (tid == 0)
|
||
tid = regcache->ptid ().pid (); /* Not a threaded program. */
|
||
|
||
if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum))
|
||
{
|
||
elf_gregset_t regs;
|
||
|
||
if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0)
|
||
perror_with_name (_("Couldn't get registers"));
|
||
|
||
amd64_supply_native_gregset (regcache, ®s, -1);
|
||
if (regnum != -1)
|
||
return;
|
||
}
|
||
|
||
if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum))
|
||
{
|
||
elf_fpregset_t fpregs;
|
||
|
||
if (have_ptrace_getregset == TRIBOOL_TRUE)
|
||
{
|
||
char xstateregs[X86_XSTATE_MAX_SIZE];
|
||
struct iovec iov;
|
||
|
||
iov.iov_base = xstateregs;
|
||
iov.iov_len = sizeof (xstateregs);
|
||
if (ptrace (PTRACE_GETREGSET, tid,
|
||
(unsigned int) NT_X86_XSTATE, (long) &iov) < 0)
|
||
perror_with_name (_("Couldn't get extended state status"));
|
||
|
||
amd64_supply_xsave (regcache, -1, xstateregs);
|
||
}
|
||
else
|
||
{
|
||
if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0)
|
||
perror_with_name (_("Couldn't get floating point status"));
|
||
|
||
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 (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 (AMD64_GSBASE_REGNUM, &base);
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
}
|
||
|
||
/* Store register REGNUM back into the child process. If REGNUM is
|
||
-1, do this for all registers (including the floating-point and SSE
|
||
registers). */
|
||
|
||
void
|
||
amd64_linux_nat_target::store_registers (struct regcache *regcache, int regnum)
|
||
{
|
||
struct gdbarch *gdbarch = regcache->arch ();
|
||
int tid;
|
||
|
||
/* GNU/Linux LWP ID's are process ID's. */
|
||
tid = regcache->ptid ().lwp ();
|
||
if (tid == 0)
|
||
tid = regcache->ptid ().pid (); /* Not a threaded program. */
|
||
|
||
if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum))
|
||
{
|
||
elf_gregset_t regs;
|
||
|
||
if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0)
|
||
perror_with_name (_("Couldn't get registers"));
|
||
|
||
amd64_collect_native_gregset (regcache, ®s, regnum);
|
||
|
||
if (ptrace (PTRACE_SETREGS, tid, 0, (long) ®s) < 0)
|
||
perror_with_name (_("Couldn't write registers"));
|
||
|
||
if (regnum != -1)
|
||
return;
|
||
}
|
||
|
||
if (regnum == -1 || !amd64_native_gregset_supplies_p (gdbarch, regnum))
|
||
{
|
||
elf_fpregset_t fpregs;
|
||
|
||
if (have_ptrace_getregset == TRIBOOL_TRUE)
|
||
{
|
||
char xstateregs[X86_XSTATE_MAX_SIZE];
|
||
struct iovec iov;
|
||
|
||
iov.iov_base = xstateregs;
|
||
iov.iov_len = sizeof (xstateregs);
|
||
if (ptrace (PTRACE_GETREGSET, tid,
|
||
(unsigned int) NT_X86_XSTATE, (long) &iov) < 0)
|
||
perror_with_name (_("Couldn't get extended state status"));
|
||
|
||
amd64_collect_xsave (regcache, regnum, xstateregs, 0);
|
||
|
||
if (ptrace (PTRACE_SETREGSET, tid,
|
||
(unsigned int) NT_X86_XSTATE, (long) &iov) < 0)
|
||
perror_with_name (_("Couldn't write extended state status"));
|
||
}
|
||
else
|
||
{
|
||
if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0)
|
||
perror_with_name (_("Couldn't get floating point status"));
|
||
|
||
amd64_collect_fxsave (regcache, regnum, &fpregs);
|
||
|
||
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 (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 (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
|
||
}
|
||
}
|
||
|
||
|
||
/* This function is called by libthread_db as part of its handling of
|
||
a request for a thread's local storage address. */
|
||
|
||
ps_err_e
|
||
ps_get_thread_area (struct ps_prochandle *ph,
|
||
lwpid_t lwpid, int idx, void **base)
|
||
{
|
||
if (gdbarch_bfd_arch_info (target_gdbarch ())->bits_per_word == 32)
|
||
{
|
||
unsigned int base_addr;
|
||
ps_err_e result;
|
||
|
||
result = x86_linux_get_thread_area (lwpid, (void *) (long) idx,
|
||
&base_addr);
|
||
if (result == PS_OK)
|
||
{
|
||
/* Extend the value to 64 bits. Here it's assumed that
|
||
a "long" and a "void *" are the same. */
|
||
(*base) = (void *) (long) base_addr;
|
||
}
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
|
||
/* 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);
|
||
gdb_assert (GS < ELF_NGREG);
|
||
switch (idx)
|
||
{
|
||
case FS:
|
||
#ifdef 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 fs;
|
||
errno = 0;
|
||
fs = ptrace (PTRACE_PEEKUSER, lwpid,
|
||
offsetof (struct user_regs_struct, fs_base), 0);
|
||
if (errno == 0)
|
||
{
|
||
*base = (void *) fs;
|
||
return PS_OK;
|
||
}
|
||
}
|
||
#endif
|
||
if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_FS) == 0)
|
||
return PS_OK;
|
||
break;
|
||
case GS:
|
||
#ifdef HAVE_STRUCT_USER_REGS_STRUCT_GS_BASE
|
||
{
|
||
unsigned long gs;
|
||
errno = 0;
|
||
gs = ptrace (PTRACE_PEEKUSER, lwpid,
|
||
offsetof (struct user_regs_struct, gs_base), 0);
|
||
if (errno == 0)
|
||
{
|
||
*base = (void *) gs;
|
||
return PS_OK;
|
||
}
|
||
}
|
||
#endif
|
||
if (ptrace (PTRACE_ARCH_PRCTL, lwpid, base, ARCH_GET_GS) == 0)
|
||
return PS_OK;
|
||
break;
|
||
default: /* Should not happen. */
|
||
return PS_BADADDR;
|
||
}
|
||
}
|
||
return PS_ERR; /* ptrace failed. */
|
||
}
|
||
|
||
|
||
/* Convert a ptrace/host siginfo object, into/from the siginfo in the
|
||
layout of the inferiors' architecture. Returns true if any
|
||
conversion was done; false otherwise. If DIRECTION is 1, then copy
|
||
from INF to PTRACE. If DIRECTION is 0, copy from PTRACE to
|
||
INF. */
|
||
|
||
bool
|
||
amd64_linux_nat_target::low_siginfo_fixup (siginfo_t *ptrace,
|
||
gdb_byte *inf,
|
||
int direction)
|
||
{
|
||
struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
|
||
|
||
/* Is the inferior 32-bit? If so, then do fixup the siginfo
|
||
object. */
|
||
if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
|
||
return amd64_linux_siginfo_fixup_common (ptrace, inf, direction,
|
||
FIXUP_32);
|
||
/* No fixup for native x32 GDB. */
|
||
else if (gdbarch_addr_bit (gdbarch) == 32 && sizeof (void *) == 8)
|
||
return amd64_linux_siginfo_fixup_common (ptrace, inf, direction,
|
||
FIXUP_X32);
|
||
else
|
||
return false;
|
||
}
|
||
|
||
void
|
||
_initialize_amd64_linux_nat (void)
|
||
{
|
||
amd64_native_gregset32_reg_offset = amd64_linux_gregset32_reg_offset;
|
||
amd64_native_gregset32_num_regs = I386_LINUX_NUM_REGS;
|
||
amd64_native_gregset64_reg_offset = amd64_linux_gregset_reg_offset;
|
||
amd64_native_gregset64_num_regs = AMD64_LINUX_NUM_REGS;
|
||
|
||
gdb_assert (ARRAY_SIZE (amd64_linux_gregset32_reg_offset)
|
||
== amd64_native_gregset32_num_regs);
|
||
|
||
linux_target = &the_amd64_linux_nat_target;
|
||
|
||
/* Add the target. */
|
||
add_inf_child_target (linux_target);
|
||
}
|