/* Xtensa GNU/Linux native support.
- Copyright (C) 2007-2015 Free Software Foundation, Inc.
+ Copyright (C) 2007-2018 Free Software Foundation, Inc.
This file is part of GDB.
#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. */
{
int i;
xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
regcache_raw_collect (regcache, gdbarch_pc_regnum (gdbarch), ®s->pc);
regcache_raw_collect (regcache,
gdbarch_tdep (gdbarch)->sar_regnum,
®s->sar);
+ if (regnum == gdbarch_tdep (gdbarch)->threadptr_regnum || regnum == -1)
+ regcache_raw_collect (regcache,
+ gdbarch_tdep (gdbarch)->threadptr_regnum,
+ ®s->threadptr);
if (regnum >=gdbarch_tdep (gdbarch)->ar_base
&& regnum < gdbarch_tdep (gdbarch)->ar_base
+ gdbarch_tdep (gdbarch)->num_aregs)
gdbarch_tdep (gdbarch)->ar_base + i,
®s->ar[i]);
}
+ if (regnum >= gdbarch_tdep (gdbarch)->a0_base
+ && regnum < gdbarch_tdep (gdbarch)->a0_base + C0_NREGS)
+ regcache_raw_collect (regcache, regnum,
+ ®s->ar[(4 * regs->windowbase + regnum
+ - gdbarch_tdep (gdbarch)->a0_base)
+ % gdbarch_tdep (gdbarch)->num_aregs]);
+ else if (regnum == -1)
+ {
+ for (i = 0; i < C0_NREGS; ++i)
+ regcache_raw_collect (regcache,
+ gdbarch_tdep (gdbarch)->a0_base + i,
+ ®s->ar[(4 * regs->windowbase + i)
+ % gdbarch_tdep (gdbarch)->num_aregs]);
+ }
}
-void
+static void
supply_gregset_reg (struct regcache *regcache,
const gdb_gregset_t *gregsetp, int regnum)
{
int i;
xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch *gdbarch = regcache->arch ();
if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
regcache_raw_supply (regcache, gdbarch_pc_regnum (gdbarch), ®s->pc);
regcache_raw_supply (regcache,
gdbarch_tdep (gdbarch)->sar_regnum,
®s->sar);
+ if (regnum == gdbarch_tdep (gdbarch)->threadptr_regnum || regnum == -1)
+ regcache_raw_supply (regcache,
+ gdbarch_tdep (gdbarch)->threadptr_regnum,
+ ®s->threadptr);
if (regnum >=gdbarch_tdep (gdbarch)->ar_base
&& regnum < gdbarch_tdep (gdbarch)->ar_base
+ gdbarch_tdep (gdbarch)->num_aregs)
gdbarch_tdep (gdbarch)->ar_base + i,
®s->ar[i]);
}
+ if (regnum >= gdbarch_tdep (gdbarch)->a0_base
+ && regnum < gdbarch_tdep (gdbarch)->a0_base + C0_NREGS)
+ regcache_raw_supply (regcache, regnum,
+ ®s->ar[(4 * regs->windowbase + regnum
+ - gdbarch_tdep (gdbarch)->a0_base)
+ % gdbarch_tdep (gdbarch)->num_aregs]);
+ else if (regnum == -1)
+ {
+ for (i = 0; i < C0_NREGS; ++i)
+ regcache_raw_supply (regcache,
+ gdbarch_tdep (gdbarch)->a0_base + i,
+ ®s->ar[(4 * regs->windowbase + i)
+ % gdbarch_tdep (gdbarch)->num_aregs]);
+ }
}
void
static void
fetch_gregs (struct regcache *regcache, int regnum)
{
- int tid = ptid_get_lwp (inferior_ptid);
- const gdb_gregset_t regs;
+ int tid = ptid_get_lwp (regcache_get_ptid (regcache));
+ gdb_gregset_t regs;
int areg;
if (ptrace (PTRACE_GETREGS, tid, 0, (long) ®s) < 0)
static void
store_gregs (struct regcache *regcache, int regnum)
{
- int tid = ptid_get_lwp (inferior_ptid);
+ int tid = ptid_get_lwp (regcache_get_ptid (regcache));
gdb_gregset_t regs;
int areg;
static void
fetch_xtregs (struct regcache *regcache, int regnum)
{
- int tid = ptid_get_lwp (inferior_ptid);
+ int tid = ptid_get_lwp (regcache_get_ptid (regcache));
const xtensa_regtable_t *ptr;
char xtregs [XTENSA_ELF_XTREG_SIZE];
static void
store_xtregs (struct regcache *regcache, int regnum)
{
- int tid = ptid_get_lwp (inferior_ptid);
+ int tid = ptid_get_lwp (regcache_get_ptid (regcache));
const xtensa_regtable_t *ptr;
char xtregs [XTENSA_ELF_XTREG_SIZE];
perror_with_name (_("Couldn't write extended registers"));
}
-void
+static void
xtensa_linux_fetch_inferior_registers (struct target_ops *ops,
struct regcache *regcache, int regnum)
{
fetch_xtregs (regcache, regnum);
}
-void
+static void
xtensa_linux_store_inferior_registers (struct target_ops *ops,
struct regcache *regcache, int regnum)
{
store_xtregs (regcache, regnum);
}
-void _initialize_xtensa_linux_nat (void);
+/* Called by libthread_db. */
+
+ps_err_e
+ps_get_thread_area (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)