/* Motorola m68k native support for GNU/Linux.
- Copyright (C) 1996-2017 Free Software Foundation, Inc.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
This file is part of GDB.
/* Defines ps_err_e, struct ps_prochandle. */
#include "gdb_proc_service.h"
+#include "inf-ptrace.h"
+
#ifndef PTRACE_GET_THREAD_AREA
#define PTRACE_GET_THREAD_AREA 25
#endif
\f
+
+class m68k_linux_nat_target final : public linux_nat_target
+{
+public:
+ /* Add our register access methods. */
+ void fetch_registers (struct regcache *, int) override;
+ void store_registers (struct regcache *, int) override;
+};
+
+static m68k_linux_nat_target the_m68k_linux_nat_target;
+
/* This table must line up with gdbarch_register_name in "m68k-tdep.c". */
static const int regmap[] =
{
static void
fetch_register (struct regcache *regcache, int regno)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
long regaddr, val;
int i;
gdb_byte buf[M68K_MAX_REGISTER_SIZE];
- int tid;
-
- /* Overload thread id onto process id. */
- tid = ptid_get_lwp (inferior_ptid);
- if (tid == 0)
- tid = ptid_get_pid (inferior_ptid); /* no thread id, just use
- process id. */
+ pid_t tid = get_ptrace_pid (regcache_get_ptid (regcache));
regaddr = 4 * regmap[regno];
for (i = 0; i < register_size (gdbarch, regno); i += sizeof (long))
else
{
for (regno = 0;
- regno < gdbarch_num_regs (get_regcache_arch (regcache));
+ regno < gdbarch_num_regs (regcache->arch ());
regno++)
{
fetch_register (regcache, regno);
static void
store_register (const struct regcache *regcache, int regno)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
long regaddr, val;
int i;
- int tid;
gdb_byte buf[M68K_MAX_REGISTER_SIZE];
-
- /* Overload thread id onto process id. */
- tid = ptid_get_lwp (inferior_ptid);
- if (tid == 0)
- tid = ptid_get_pid (inferior_ptid); /* no thread id, just use
- process id. */
+ pid_t tid = get_ptrace_pid (regcache_get_ptid (regcache));
regaddr = 4 * regmap[regno];
else
{
for (regno = 0;
- regno < gdbarch_num_regs (get_regcache_arch (regcache));
+ regno < gdbarch_num_regs (regcache->arch ());
regno++)
{
store_register (regcache, regno);
void
supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
int regi;
void
supply_fpregset (struct regcache *regcache, const elf_fpregset_t *fpregsetp)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
int regi;
for (regi = gdbarch_fp0_regnum (gdbarch);
fill_fpregset (const struct regcache *regcache,
elf_fpregset_t *fpregsetp, int regno)
{
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
int i;
/* Fill in the floating-point registers. */
this for all registers (including the floating point and SSE
registers). */
-static void
-m68k_linux_fetch_inferior_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+void
+m68k_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
{
- int tid;
+ pid_t tid;
/* Use the old method of peeking around in `struct user' if the
GETREGS request isn't available. */
return;
}
- /* GNU/Linux LWP ID's are process ID's. */
- tid = ptid_get_lwp (inferior_ptid);
- if (tid == 0)
- tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
+ tid = get_ptrace_pid (regcache_get_ptid (regcache));
/* Use the PTRACE_GETFPXREGS request whenever possible, since it
transfers more registers in one system call, and we'll cache the
/* Store register REGNO back into the child process. If REGNO is -1,
do this for all registers (including the floating point and SSE
registers). */
-static void
-m68k_linux_store_inferior_registers (struct target_ops *ops,
- struct regcache *regcache, int regno)
+void
+m68k_linux_nat_target::store_registers (struct regcache *regcache, int regno)
{
- int tid;
+ pid_t tid;
/* Use the old method of poking around in `struct user' if the
SETREGS request isn't available. */
return;
}
- /* GNU/Linux LWP ID's are process ID's. */
- tid = ptid_get_lwp (inferior_ptid);
- if (tid == 0)
- tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
+ tid = get_ptrace_pid (regcache_get_ptid (regcache));
/* Use the PTRACE_SETFPREGS requests whenever possible, since it
transfers more registers in one system call. But remember that
return PS_OK;
}
-\f
-
-void _initialize_m68k_linux_nat (void);
void
_initialize_m68k_linux_nat (void)
{
- struct target_ops *t;
-
- /* Fill in the generic GNU/Linux methods. */
- t = linux_target ();
-
- /* Add our register access methods. */
- t->to_fetch_registers = m68k_linux_fetch_inferior_registers;
- t->to_store_registers = m68k_linux_store_inferior_registers;
-
/* Register the target. */
- linux_nat_add_target (t);
+ linux_target = &the_m68k_linux_nat_target;
+ add_inf_child_target (&the_m68k_linux_nat_target);
}