/* Motorola m68k native support for GNU/Linux.
- Copyright (C) 1996, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2008, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of GDB.
#include "inferior.h"
#include "language.h"
#include "gdbcore.h"
-#include "gdb_string.h"
#include "regcache.h"
#include "target.h"
#include "linux-nat.h"
#include "m68k-tdep.h"
-#include <sys/param.h>
#include <sys/dir.h>
#include <signal.h>
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
#include <sys/user.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#endif
#include <sys/file.h>
-#include "gdb_stat.h"
+#include <sys/stat.h>
#include "floatformat.h"
-#include "target.h"
-
-/* Prototypes for supply_gregset etc. */
+/* Prototypes for supply_gregset etc. */
#include "gregset.h"
+
+/* Defines ps_err_e, struct ps_prochandle. */
+#include "gdb_proc_service.h"
+
+#ifndef PTRACE_GET_THREAD_AREA
+#define PTRACE_GET_THREAD_AREA 25
+#endif
\f
/* This table must line up with gdbarch_register_name in "m68k-tdep.c". */
static const int regmap[] =
#define NUM_GREGS (18)
#define MAX_NUM_REGS (NUM_GREGS + 11)
-int
+static int
getregs_supplies (int regno)
{
return 0 <= regno && regno < NUM_GREGS;
}
-int
+static int
getfpregs_supplies (int regno)
{
return M68K_FP0_REGNUM <= regno && regno <= M68K_FPI_REGNUM;
}
/* Does the current host support the GETREGS request? */
-int have_ptrace_getregs =
+static int have_ptrace_getregs =
#ifdef HAVE_PTRACE_GETREGS
1
#else
fetch_register (struct regcache *regcache, int regno)
{
struct gdbarch *gdbarch = get_regcache_arch (regcache);
- long regaddr;
+ long regaddr, val;
int i;
- char buf[MAX_REGISTER_SIZE];
+ gdb_byte buf[MAX_REGISTER_SIZE];
int tid;
- /* Overload thread id onto process id */
- tid = TIDGET (inferior_ptid);
+ /* Overload thread id onto process id. */
+ tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid); /* no thread id, just use process id */
+ tid = ptid_get_pid (inferior_ptid); /* no thread id, just use
+ process id. */
regaddr = 4 * regmap[regno];
for (i = 0; i < register_size (gdbarch, regno); i += sizeof (long))
{
errno = 0;
- *(long *) &buf[i] = ptrace (PTRACE_PEEKUSER, tid, regaddr, 0);
+ val = ptrace (PTRACE_PEEKUSER, tid, regaddr, 0);
+ memcpy (&buf[i], &val, sizeof (long));
regaddr += sizeof (long);
if (errno != 0)
error (_("Couldn't read register %s (#%d): %s."),
/* Fetch register values from the inferior.
If REGNO is negative, do this for all registers.
- Otherwise, REGNO specifies which register (so we can save time). */
+ Otherwise, REGNO specifies which register (so we can save time). */
static void
old_fetch_inferior_registers (struct regcache *regcache, int regno)
}
}
-/* Store one register. */
+/* Store one register. */
static void
store_register (const struct regcache *regcache, int regno)
{
struct gdbarch *gdbarch = get_regcache_arch (regcache);
- long regaddr;
+ long regaddr, val;
int i;
int tid;
- char buf[MAX_REGISTER_SIZE];
+ gdb_byte buf[MAX_REGISTER_SIZE];
- /* Overload thread id onto process id */
- tid = TIDGET (inferior_ptid);
+ /* Overload thread id onto process id. */
+ tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid); /* no thread id, just use process id */
+ tid = ptid_get_pid (inferior_ptid); /* no thread id, just use
+ process id. */
regaddr = 4 * regmap[regno];
- /* Put the contents of regno into a local buffer */
+ /* Put the contents of regno into a local buffer. */
regcache_raw_collect (regcache, regno, buf);
- /* Store the local buffer into the inferior a chunk at the time. */
+ /* Store the local buffer into the inferior a chunk at the time. */
for (i = 0; i < register_size (gdbarch, regno); i += sizeof (long))
{
errno = 0;
- ptrace (PTRACE_POKEUSER, tid, regaddr, *(long *) &buf[i]);
+ memcpy (&val, &buf[i], sizeof (long));
+ ptrace (PTRACE_POKEUSER, tid, regaddr, val);
regaddr += sizeof (long);
if (errno != 0)
error (_("Couldn't write register %s (#%d): %s."),
\f
/* Given a pointer to a general register set in /proc format
(elf_gregset_t *), unpack the register contents and supply
- them as gdb's idea of the current register values. */
+ them as gdb's idea of the current register values. */
void
supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
#else
-static void fetch_regs (struct regcache *regcache, int tid) {}
-static void store_regs (const struct regcache *regcache, int tid, int regno) {}
+static void fetch_regs (struct regcache *regcache, int tid)
+{
+}
+
+static void store_regs (const struct regcache *regcache, int tid, int regno)
+{
+}
#endif
#else
-static void fetch_fpregs (struct regcache *regcache, int tid) {}
-static void store_fpregs (const struct regcache *regcache, int tid, int regno) {}
+static void fetch_fpregs (struct regcache *regcache, int tid)
+{
+}
+
+static void store_fpregs (const struct regcache *regcache, int tid, int regno)
+{
+}
#endif
\f
}
/* GNU/Linux LWP ID's are process ID's. */
- tid = TIDGET (inferior_ptid);
+ tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid); /* Not a threaded program. */
+ tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
/* Use the PTRACE_GETFPXREGS request whenever possible, since it
transfers more registers in one system call, and we'll cache the
}
/* GNU/Linux LWP ID's are process ID's. */
- tid = TIDGET (inferior_ptid);
+ tid = ptid_get_lwp (inferior_ptid);
if (tid == 0)
- tid = PIDGET (inferior_ptid); /* Not a threaded program. */
+ tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
/* Use the PTRACE_SETFPREGS requests whenever possible, since it
transfers more registers in one system call. But remember that
_("Got request to store bad register number %d."), regno);
}
\f
-/* Interpreting register set info found in core files. */
-
-/* Provide registers to GDB from a core file.
- (We can't use the generic version of this function in
- core-regset.c, because we need to use elf_gregset_t instead of
- gregset_t.)
+/* Fetch the thread-local storage pointer for libthread_db. */
- CORE_REG_SECT points to an array of bytes, which are the contents
- of a `note' from a core file which BFD thinks might contain
- register contents. CORE_REG_SIZE is its size.
-
- WHICH says which register set corelow suspects this is:
- 0 --- the general-purpose register set, in elf_gregset_t format
- 2 --- the floating-point register set, in elf_fpregset_t format
-
- REG_ADDR isn't used on GNU/Linux. */
-
-static void
-fetch_core_registers (struct regcache *regcache,
- char *core_reg_sect, unsigned core_reg_size,
- int which, CORE_ADDR reg_addr)
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+ lwpid_t lwpid, int idx, void **base)
{
- elf_gregset_t gregset;
- elf_fpregset_t fpregset;
-
- switch (which)
- {
- case 0:
- if (core_reg_size != sizeof (gregset))
- warning (_("Wrong size gregset in core file."));
- else
- {
- memcpy (&gregset, core_reg_sect, sizeof (gregset));
- supply_gregset (regcache, (const elf_gregset_t *) &gregset);
- }
- break;
+ if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) < 0)
+ return PS_ERR;
- case 2:
- if (core_reg_size != sizeof (fpregset))
- warning (_("Wrong size fpregset in core file."));
- else
- {
- memcpy (&fpregset, core_reg_sect, sizeof (fpregset));
- supply_fpregset (regcache, (const elf_fpregset_t *) &fpregset);
- }
- break;
+ /* IDX is the bias from the thread pointer to the beginning of the
+ thread descriptor. It has to be subtracted due to implementation
+ quirks in libthread_db. */
+ *base = (char *) *base - idx;
- default:
- /* We've covered all the kinds of registers we know about here,
- so this must be something we wouldn't know what to do with
- anyway. Just ignore it. */
- break;
- }
+ return PS_OK;
}
\f
-/* Register that we are able to handle GNU/Linux ELF core file
- formats. */
-
-static struct core_fns linux_elf_core_fns =
-{
- bfd_target_elf_flavour, /* core_flavour */
- default_check_format, /* check_format */
- default_core_sniffer, /* core_sniffer */
- fetch_core_registers, /* core_read_registers */
- NULL /* next */
-};
-
void _initialize_m68k_linux_nat (void);
void
/* Register the target. */
linux_nat_add_target (t);
-
- deprecated_add_core_fns (&linux_elf_core_fns);
}