bfd_set_input_error
[deliverable/binutils-gdb.git] / gdb / xtensa-linux-nat.c
index 191ccefbf166267af823cea753f26bf1930c9ad1..b8366c55a4144948d409c058fbf4c296ca188d6e 100644 (file)
@@ -1,6 +1,6 @@
 /* Xtensa GNU/Linux native support.
 
-   Copyright (C) 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 2007-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_string.h"
 #include "frame.h"
 #include "inferior.h"
 #include "gdbcore.h"
 #include "regcache.h"
-#include "gdb_assert.h"
 #include "target.h"
 #include "linux-nat.h"
-
-#include <stdint.h>
 #include <sys/types.h>
-#include <sys/param.h>
 #include <signal.h>
 #include <sys/user.h>
 #include <sys/ioctl.h>
 #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"
 
-int
-get_thread_id (ptid_t ptid)
-{
-  int tid = TIDGET (ptid);
-  if (0 == tid)
-    tid = PIDGET (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)
@@ -93,6 +82,10 @@ fill_gregset (const struct regcache *regcache,
     regcache_raw_collect (regcache,
                          gdbarch_tdep (gdbarch)->sar_regnum,
                          &regs->sar);
+  if (regnum == gdbarch_tdep (gdbarch)->threadptr_regnum || regnum == -1)
+    regcache_raw_collect (regcache,
+                         gdbarch_tdep (gdbarch)->threadptr_regnum,
+                         &regs->threadptr);
   if (regnum >=gdbarch_tdep (gdbarch)->ar_base
       && regnum < gdbarch_tdep (gdbarch)->ar_base
                    + gdbarch_tdep (gdbarch)->num_aregs)
@@ -105,9 +98,23 @@ fill_gregset (const struct regcache *regcache,
                              gdbarch_tdep (gdbarch)->ar_base + i,
                              &regs->ar[i]);
     }
+  if (regnum >= gdbarch_tdep (gdbarch)->a0_base
+      && regnum < gdbarch_tdep (gdbarch)->a0_base + C0_NREGS)
+    regcache_raw_collect (regcache, regnum,
+                         &regs->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,
+                             &regs->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)
 {
@@ -145,6 +152,10 @@ supply_gregset_reg (struct regcache *regcache,
     regcache_raw_supply (regcache,
                          gdbarch_tdep (gdbarch)->sar_regnum,
                          &regs->sar);
+  if (regnum == gdbarch_tdep (gdbarch)->threadptr_regnum || regnum == -1)
+    regcache_raw_supply (regcache,
+                         gdbarch_tdep (gdbarch)->threadptr_regnum,
+                         &regs->threadptr);
   if (regnum >=gdbarch_tdep (gdbarch)->ar_base
       && regnum < gdbarch_tdep (gdbarch)->ar_base
                    + gdbarch_tdep (gdbarch)->num_aregs)
@@ -157,6 +168,20 @@ supply_gregset_reg (struct regcache *regcache,
                              gdbarch_tdep (gdbarch)->ar_base + i,
                              &regs->ar[i]);
     }
+  if (regnum >= gdbarch_tdep (gdbarch)->a0_base
+      && regnum < gdbarch_tdep (gdbarch)->a0_base + C0_NREGS)
+    regcache_raw_supply (regcache, regnum,
+                        &regs->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,
+                            &regs->ar[(4 * regs->windowbase + i)
+                            % gdbarch_tdep (gdbarch)->num_aregs]);
+    }
 }
 
 void
@@ -185,8 +210,8 @@ supply_fpregset (struct regcache *regcache,
 static void
 fetch_gregs (struct regcache *regcache, int regnum)
 {
-  int tid = GET_THREAD_ID (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) &regs) < 0)
@@ -204,7 +229,7 @@ fetch_gregs (struct regcache *regcache, int regnum)
 static void
 store_gregs (struct regcache *regcache, int regnum)
 {
-  int tid = GET_THREAD_ID (inferior_ptid);
+  int tid = ptid_get_lwp (regcache_get_ptid (regcache));
   gdb_gregset_t regs;
   int areg;
 
@@ -232,7 +257,7 @@ static int xtreg_high;
 static void
 fetch_xtregs (struct regcache *regcache, int regnum)
 {
-  int tid = GET_THREAD_ID (inferior_ptid);
+  int tid = ptid_get_lwp (regcache_get_ptid (regcache));
   const xtensa_regtable_t *ptr;
   char xtregs [XTENSA_ELF_XTREG_SIZE];
 
@@ -248,7 +273,7 @@ fetch_xtregs (struct regcache *regcache, int regnum)
 static void
 store_xtregs (struct regcache *regcache, int regnum)
 {
-  int tid = GET_THREAD_ID (inferior_ptid);
+  int tid = ptid_get_lwp (regcache_get_ptid (regcache));
   const xtensa_regtable_t *ptr;
   char xtregs [XTENSA_ELF_XTREG_SIZE];
 
@@ -264,7 +289,7 @@ store_xtregs (struct regcache *regcache, int regnum)
     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)
 {
@@ -279,7 +304,7 @@ xtensa_linux_fetch_inferior_registers (struct target_ops *ops,
     fetch_xtregs (regcache, regnum);
 }
 
-void
+static void
 xtensa_linux_store_inferior_registers (struct target_ops *ops,
                                       struct regcache *regcache, int regnum)
 {
@@ -294,7 +319,24 @@ xtensa_linux_store_inferior_registers (struct target_ops *ops,
     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, &regs) != 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)
This page took 0.028722 seconds and 4 git commands to generate.