#include "gdb_wait.h"
#include <fcntl.h>
#include <sys/procfs.h>
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
#include <asm/ptrace.h>
#include "gregset.h"
#include "xtensa-tdep.h"
+/* Defines ps_err_e, struct ps_prochandle. */
+#include "gdb_proc_service.h"
+
/* Extended register set depends on hardware configs.
Keeping these definitions separately allows to introduce
hardware-specific overlays. */
#include "xtensa-xtregs.c"
-static int
-get_thread_id (ptid_t ptid)
-{
- int tid = ptid_get_lwp (ptid);
- if (0 == tid)
- tid = ptid_get_pid (ptid);
- return tid;
-}
-#define GET_THREAD_ID(PTID) get_thread_id (PTID)
-
void
fill_gregset (const struct regcache *regcache,
gdb_gregset_t *gregsetp, int regnum)
static void
fetch_gregs (struct regcache *regcache, int regnum)
{
- int tid = GET_THREAD_ID (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
const gdb_gregset_t regs;
int areg;
static void
store_gregs (struct regcache *regcache, int regnum)
{
- int tid = GET_THREAD_ID (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
gdb_gregset_t regs;
int areg;
static void
fetch_xtregs (struct regcache *regcache, int regnum)
{
- int tid = GET_THREAD_ID (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
const xtensa_regtable_t *ptr;
char xtregs [XTENSA_ELF_XTREG_SIZE];
static void
store_xtregs (struct regcache *regcache, int regnum)
{
- int tid = GET_THREAD_ID (inferior_ptid);
+ int tid = ptid_get_lwp (inferior_ptid);
const xtensa_regtable_t *ptr;
char xtregs [XTENSA_ELF_XTREG_SIZE];
store_xtregs (regcache, regnum);
}
+/* Called by libthread_db. */
+
+ps_err_e
+ps_get_thread_area (const struct ps_prochandle *ph,
+ lwpid_t lwpid, int idx, void **base)
+{
+ xtensa_elf_gregset_t regs;
+
+ if (ptrace (PTRACE_GETREGS, lwpid, NULL, ®s) != 0)
+ return PS_ERR;
+
+ /* 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 = (void *) ((char *) regs.threadptr - idx);
+
+ return PS_OK;
+}
+
void _initialize_xtensa_linux_nat (void);
void