Fix M68HC11_NUM_REGS
[deliverable/binutils-gdb.git] / gdb / ia64-linux-nat.c
index 9b5fbf3d8ae3471895d2aa4c560a6716968bbc05..277e7cb85a53dceadfdf40b93dcc2e00c96bd133 100644 (file)
@@ -1,7 +1,7 @@
 /* Functions specific to running gdb native on IA-64 running
    GNU/Linux.
 
-   Copyright (C) 1999-2012 Free Software Foundation, Inc.
+   Copyright (C) 1999-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -19,7 +19,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "gdb_string.h"
 #include "inferior.h"
 #include "target.h"
 #include "gdbcore.h"
@@ -28,7 +27,7 @@
 #include "linux-nat.h"
 
 #include <signal.h>
-#include <sys/ptrace.h>
+#include "nat/gdb_ptrace.h"
 #include "gdb_wait.h"
 #ifdef HAVE_SYS_REG_H
 #include <sys/reg.h>
@@ -42,6 +41,8 @@
 /* Prototypes for supply_gregset etc.  */
 #include "gregset.h"
 
+#include "inf-ptrace.h"
+
 /* These must match the order of the register names.
 
    Some sort of lookup table is needed because the offsets associated
@@ -511,9 +512,9 @@ store_debug_register (ptid_t ptid, int idx, long val)
 {
   int tid;
 
-  tid = TIDGET (ptid);
+  tid = ptid_get_lwp (ptid);
   if (tid == 0)
-    tid = PIDGET (ptid);
+    tid = ptid_get_pid (ptid);
 
   (void) ptrace (PT_WRITE_U, tid, (PTRACE_TYPE_ARG3) (PT_DBR + 8 * idx), val);
 }
@@ -542,7 +543,9 @@ is_power_of_2 (int val)
 }
 
 static int
-ia64_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
+ia64_linux_insert_watchpoint (struct target_ops *self,
+                             CORE_ADDR addr, int len,
+                             enum target_hw_bp_type type,
                              struct expression *cond)
 {
   struct lwp_info *lp;
@@ -569,7 +572,7 @@ ia64_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
   dbr_addr = (long) addr;
   dbr_mask = (~(len - 1) & 0x00ffffffffffffffL);  /* construct mask to match */
   dbr_mask |= 0x0800000000000000L;           /* Only match privilege level 3 */
-  switch (rw)
+  switch (type)
     {
     case hw_write:
       dbr_mask |= (1L << 62);                  /* Set w bit */
@@ -596,7 +599,9 @@ ia64_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
 }
 
 static int
-ia64_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
+ia64_linux_remove_watchpoint (struct target_ops *self,
+                             CORE_ADDR addr, int len,
+                             enum target_hw_bp_type type,
                              struct expression *cond)
 {
   int idx;
@@ -669,14 +674,16 @@ ia64_linux_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
 }
 
 static int
-ia64_linux_stopped_by_watchpoint (void)
+ia64_linux_stopped_by_watchpoint (struct target_ops *ops)
 {
   CORE_ADDR addr;
-  return ia64_linux_stopped_data_address (&current_target, &addr);
+  return ia64_linux_stopped_data_address (ops, &addr);
 }
 
 static int
-ia64_linux_can_use_hw_breakpoint (int type, int cnt, int othertype)
+ia64_linux_can_use_hw_breakpoint (struct target_ops *self,
+                                 enum bptype type,
+                                 int cnt, int othertype)
 {
   return 1;
 }
@@ -687,11 +694,12 @@ ia64_linux_can_use_hw_breakpoint (int type, int cnt, int othertype)
 static void
 ia64_linux_fetch_register (struct regcache *regcache, int regnum)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   CORE_ADDR addr;
   size_t size;
   PTRACE_TYPE_RET *buf;
-  int pid, i;
+  pid_t pid;
+  int i;
 
   /* r0 cannot be fetched but is always zero.  */
   if (regnum == IA64_GR0_REGNUM)
@@ -730,18 +738,14 @@ ia64_linux_fetch_register (struct regcache *regcache, int regnum)
       return;
     }
 
-  /* Cater for systems like GNU/Linux, that implement threads as
-     separate processes.  */
-  pid = ptid_get_lwp (inferior_ptid);
-  if (pid == 0)
-    pid = ptid_get_pid (inferior_ptid);
+  pid = get_ptrace_pid (regcache_get_ptid (regcache));
 
   /* This isn't really an address, but ptrace thinks of it as one.  */
   addr = ia64_register_addr (gdbarch, regnum);
   size = register_size (gdbarch, regnum);
 
   gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
-  buf = alloca (size);
+  buf = (PTRACE_TYPE_RET *) alloca (size);
 
   /* Read the register contents from the inferior a chunk at a time.  */
   for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++)
@@ -767,7 +771,7 @@ ia64_linux_fetch_registers (struct target_ops *ops,
 {
   if (regnum == -1)
     for (regnum = 0;
-        regnum < gdbarch_num_regs (get_regcache_arch (regcache));
+        regnum < gdbarch_num_regs (regcache->arch ());
         regnum++)
       ia64_linux_fetch_register (regcache, regnum);
   else
@@ -779,27 +783,24 @@ ia64_linux_fetch_registers (struct target_ops *ops,
 static void
 ia64_linux_store_register (const struct regcache *regcache, int regnum)
 {
-  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  struct gdbarch *gdbarch = regcache->arch ();
   CORE_ADDR addr;
   size_t size;
   PTRACE_TYPE_RET *buf;
-  int pid, i;
+  pid_t pid;
+  int i;
 
   if (ia64_cannot_store_register (gdbarch, regnum))
     return;
 
-  /* Cater for systems like GNU/Linux, that implement threads as
-     separate processes.  */
-  pid = ptid_get_lwp (inferior_ptid);
-  if (pid == 0)
-    pid = ptid_get_pid (inferior_ptid);
+  pid = get_ptrace_pid (regcache_get_ptid (regcache));
 
   /* This isn't really an address, but ptrace thinks of it as one.  */
   addr = ia64_register_addr (gdbarch, regnum);
   size = register_size (gdbarch, regnum);
 
   gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
-  buf = alloca (size);
+  buf = (PTRACE_TYPE_RET *) alloca (size);
 
   /* Write the register contents into the inferior a chunk at a time.  */
   regcache_raw_collect (regcache, regnum, buf);
@@ -825,7 +826,7 @@ ia64_linux_store_registers (struct target_ops *ops,
 {
   if (regnum == -1)
     for (regnum = 0;
-        regnum < gdbarch_num_regs (get_regcache_arch (regcache));
+        regnum < gdbarch_num_regs (regcache->arch ());
         regnum++)
       ia64_linux_store_register (regcache, regnum);
   else
@@ -833,22 +834,49 @@ ia64_linux_store_registers (struct target_ops *ops,
 }
 
 
-static LONGEST (*super_xfer_partial) (struct target_ops *, enum target_object,
-                                     const char *, gdb_byte *,
-                                     const gdb_byte *, ULONGEST, LONGEST);
+static target_xfer_partial_ftype *super_xfer_partial;
+
+/* Implement the to_xfer_partial target_ops method.  */
 
-static LONGEST 
+static enum target_xfer_status
 ia64_linux_xfer_partial (struct target_ops *ops,
                         enum target_object object,
                         const char *annex,
                         gdb_byte *readbuf, const gdb_byte *writebuf,
-                        ULONGEST offset, LONGEST len)
+                        ULONGEST offset, ULONGEST len,
+                        ULONGEST *xfered_len)
 {
-  if (object == TARGET_OBJECT_UNWIND_TABLE && writebuf == NULL && offset == 0)
-    return syscall (__NR_getunwind, readbuf, len);
+  if (object == TARGET_OBJECT_UNWIND_TABLE && readbuf != NULL)
+    {
+      static long gate_table_size;
+      gdb_byte *tmp_buf;
+      long res;
+
+      /* Probe for the table size once.  */
+      if (gate_table_size == 0)
+        gate_table_size = syscall (__NR_getunwind, NULL, 0);
+      if (gate_table_size < 0)
+       return TARGET_XFER_E_IO;
+
+      if (offset >= gate_table_size)
+       return TARGET_XFER_EOF;
+
+      tmp_buf = (gdb_byte *) alloca (gate_table_size);
+      res = syscall (__NR_getunwind, tmp_buf, gate_table_size);
+      if (res < 0)
+       return TARGET_XFER_E_IO;
+      gdb_assert (res == gate_table_size);
+
+      if (offset + len > gate_table_size)
+       len = gate_table_size - offset;
+
+      memcpy (readbuf, tmp_buf + offset, len);
+      *xfered_len = len;
+      return TARGET_XFER_OK;
+    }
 
   return super_xfer_partial (ops, object, annex, readbuf, writebuf,
-                            offset, len);
+                            offset, len, xfered_len);
 }
 
 /* For break.b instruction ia64 CPU forgets the immediate value and generates
@@ -863,8 +891,6 @@ ia64_linux_status_is_event (int status)
                                 || WSTOPSIG (status) == SIGILL);
 }
 
-void _initialize_ia64_linux_nat (void);
-
 void
 _initialize_ia64_linux_nat (void)
 {
This page took 0.029776 seconds and 4 git commands to generate.