daily update
[binutils-gdb.git] / gdb / arm-linux-nat.c
index 43f4fdec60b799f1297eadf6dd2d13b995cc574d..a92642d0721c435ce8b68f9eed90eb3d175e1404 100644 (file)
@@ -1,6 +1,5 @@
 /* GNU/Linux on ARM native support.
-   Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009,
-   2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1999-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -20,7 +19,7 @@
 #include "defs.h"
 #include "inferior.h"
 #include "gdbcore.h"
-#include "gdb_string.h"
+#include <string.h>
 #include "regcache.h"
 #include "target.h"
 #include "linux-nat.h"
 /* Defines ps_err_e, struct ps_prochandle.  */
 #include "gdb_proc_service.h"
 
-#include "features/arm-with-iwmmxt.c"
-#include "features/arm-with-vfpv2.c"
-#include "features/arm-with-vfpv3.c"
-#include "features/arm-with-neon.c"
-
 #ifndef PTRACE_GET_THREAD_AREA
 #define PTRACE_GET_THREAD_AREA 22
 #endif
 #define PTRACE_SETHBPREGS 30
 #endif
 
-/* These are in <asm/elf.h> in current kernels.  */
-#define HWCAP_VFP       64
-#define HWCAP_IWMMXT    512
-#define HWCAP_NEON      4096
-#define HWCAP_VFPv3     8192
-#define HWCAP_VFPv3D16  16384
-
 /* A flag for whether the WMMX registers are available.  */
 static int arm_linux_has_wmmx_registers;
 
@@ -84,34 +71,18 @@ static int arm_linux_vfp_register_count;
 
 extern int arm_apcs_32;
 
-/* The following variables are used to determine the version of the
-   underlying GNU/Linux operating system.  Examples:
-
-   GNU/Linux 2.0.35             GNU/Linux 2.2.12
-   os_version = 0x00020023      os_version = 0x0002020c
-   os_major = 2                 os_major = 2
-   os_minor = 0                 os_minor = 2
-   os_release = 35              os_release = 12
-
-   Note: os_version = (os_major << 16) | (os_minor << 8) | os_release
-
-   These are initialized using get_linux_version() from
-   _initialize_arm_linux_nat().  */
-
-static unsigned int os_version, os_major, os_minor, os_release;
-
 /* On GNU/Linux, threads are implemented as pseudo-processes, in which
    case we may be tracing more than one process at a time.  In that
    case, inferior_ptid will contain the main process ID and the
    individual thread (process) ID.  get_thread_id () is used to get
    the thread id if it's available, and the process id otherwise.  */
 
-int
+static int
 get_thread_id (ptid_t ptid)
 {
-  int tid = TIDGET (ptid);
+  int tid = ptid_get_lwp (ptid);
   if (0 == tid)
-    tid = PIDGET (ptid);
+    tid = ptid_get_pid (ptid);
   return tid;
 }
 
@@ -656,31 +627,6 @@ ps_get_thread_area (const struct ps_prochandle *ph,
   return PS_OK;
 }
 
-static unsigned int
-get_linux_version (unsigned int *vmajor,
-                  unsigned int *vminor,
-                  unsigned int *vrelease)
-{
-  struct utsname info;
-  char *pmajor, *pminor, *prelease, *tail;
-
-  if (-1 == uname (&info))
-    {
-      warning (_("Unable to determine GNU/Linux version."));
-      return -1;
-    }
-
-  pmajor = strtok (info.release, ".");
-  pminor = strtok (NULL, ".");
-  prelease = strtok (NULL, ".");
-
-  *vmajor = (unsigned int) strtoul (pmajor, &tail, 0);
-  *vminor = (unsigned int) strtoul (pminor, &tail, 0);
-  *vrelease = (unsigned int) strtoul (prelease, &tail, 0);
-
-  return ((*vmajor << 16) | (*vminor << 8) | *vrelease);
-}
-
 static const struct target_desc *
 arm_linux_read_description (struct target_ops *ops)
 {
@@ -690,14 +636,12 @@ arm_linux_read_description (struct target_ops *ops)
 
   if (target_auxv_search (ops, AT_HWCAP, &arm_hwcap) != 1)
     {
-      return NULL;
+      return ops->beneath->to_read_description (ops->beneath);
     }
 
   if (arm_hwcap & HWCAP_IWMMXT)
     {
       arm_linux_has_wmmx_registers = 1;
-      if (tdesc_arm_with_iwmmxt == NULL)
-       initialize_tdesc_arm_with_iwmmxt ();
       return tdesc_arm_with_iwmmxt;
     }
 
@@ -712,28 +656,22 @@ arm_linux_read_description (struct target_ops *ops)
       if (arm_hwcap & HWCAP_NEON)
        {
          arm_linux_vfp_register_count = 32;
-         if (tdesc_arm_with_neon == NULL)
-           initialize_tdesc_arm_with_neon ();
          result = tdesc_arm_with_neon;
        }
       else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3)
        {
          arm_linux_vfp_register_count = 32;
-         if (tdesc_arm_with_vfpv3 == NULL)
-           initialize_tdesc_arm_with_vfpv3 ();
          result = tdesc_arm_with_vfpv3;
        }
       else
        {
          arm_linux_vfp_register_count = 16;
-         if (tdesc_arm_with_vfpv2 == NULL)
-           initialize_tdesc_arm_with_vfpv2 ();
          result = tdesc_arm_with_vfpv2;
        }
 
       /* Now make sure that the kernel supports reading these
         registers.  Support was added in 2.6.30.  */
-      pid = GET_LWP (inferior_ptid);
+      pid = ptid_get_lwp (inferior_ptid);
       errno = 0;
       buf = alloca (VFP_REGS_SIZE);
       if (ptrace (PTRACE_GETVFPREGS, pid, 0, buf) < 0
@@ -743,7 +681,7 @@ arm_linux_read_description (struct target_ops *ops)
       return result;
     }
 
-  return NULL;
+  return ops->beneath->to_read_description (ops->beneath);
 }
 
 /* Information describing the hardware breakpoint capabilities.  */
@@ -809,7 +747,8 @@ arm_linux_get_hw_watchpoint_count (void)
 /* Have we got a free break-/watch-point available for use?  Returns -1 if
    there is not an appropriate resource available, otherwise returns 1.  */
 static int
-arm_linux_can_use_hw_breakpoint (int type, int cnt, int ot)
+arm_linux_can_use_hw_breakpoint (struct target_ops *self,
+                                int type, int cnt, int ot)
 {
   if (type == bp_hardware_watchpoint || type == bp_read_watchpoint
       || type == bp_access_watchpoint || type == bp_watchpoint)
@@ -958,11 +897,17 @@ arm_linux_hw_breakpoint_initialize (struct gdbarch *gdbarch,
   /* We have to create a mask for the control register which says which bits
      of the word pointed to by address to break on.  */
   if (arm_pc_is_thumb (gdbarch, address))
-    mask = 0x3 << (address & 2);
+    {
+      mask = 0x3;
+      address &= ~1;
+    }
   else
-    mask = 0xf;
+    {
+      mask = 0xf;
+      address &= ~3;
+    }
 
-  p->address = (unsigned int) (address & ~3);
+  p->address = (unsigned int) address;
   p->control = arm_hwbp_control_initialize (mask, arm_hwbp_break, 1);
 }
 
@@ -1092,10 +1037,10 @@ arm_linux_remove_hw_breakpoint1 (const struct arm_linux_hw_breakpoint *bpt,
 
 /* Insert a Hardware breakpoint.  */
 static int
-arm_linux_insert_hw_breakpoint (struct gdbarch *gdbarch, 
+arm_linux_insert_hw_breakpoint (struct target_ops *self,
+                               struct gdbarch *gdbarch, 
                                struct bp_target_info *bp_tgt)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1103,18 +1048,18 @@ arm_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
     return -1;
 
   arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_insert_hw_breakpoint1 (&p, TIDGET (ptid), 0);
+  ALL_LWPS (lp)
+    arm_linux_insert_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 0);
 
   return 0;
 }
 
 /* Remove a hardware breakpoint.  */
 static int
-arm_linux_remove_hw_breakpoint (struct gdbarch *gdbarch, 
+arm_linux_remove_hw_breakpoint (struct target_ops *self,
+                               struct gdbarch *gdbarch, 
                                struct bp_target_info *bp_tgt)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1122,8 +1067,8 @@ arm_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
     return -1;
 
   arm_linux_hw_breakpoint_initialize (gdbarch, bp_tgt, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_remove_hw_breakpoint1 (&p, TIDGET (ptid), 0);
+  ALL_LWPS (lp)
+    arm_linux_remove_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 0);
 
   return 0;
 }
@@ -1131,7 +1076,8 @@ arm_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
 /* Are we able to use a hardware watchpoint for the LEN bytes starting at 
    ADDR?  */
 static int
-arm_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+arm_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
+                                      CORE_ADDR addr, int len)
 {
   const struct arm_linux_hwbp_cap *cap = arm_linux_get_hwbp_cap ();
   CORE_ADDR max_wp_length, aligned_addr;
@@ -1163,10 +1109,10 @@ arm_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
 
 /* Insert a Hardware breakpoint.  */
 static int
-arm_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
+arm_linux_insert_watchpoint (struct target_ops *self,
+                            CORE_ADDR addr, int len, int rw,
                             struct expression *cond)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1174,18 +1120,18 @@ arm_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw,
     return -1;
 
   arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_insert_hw_breakpoint1 (&p, TIDGET (ptid), 1);
+  ALL_LWPS (lp)
+    arm_linux_insert_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 1);
 
   return 0;
 }
 
 /* Remove a hardware breakpoint.  */
 static int
-arm_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
+arm_linux_remove_watchpoint (struct target_ops *self,
+                            CORE_ADDR addr, int len, int rw,
                             struct expression *cond)
 {
-  ptid_t ptid;
   struct lwp_info *lp;
   struct arm_linux_hw_breakpoint p;
 
@@ -1193,8 +1139,8 @@ arm_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
     return -1;
 
   arm_linux_hw_watchpoint_initialize (addr, len, rw, &p);
-  ALL_LWPS (lp, ptid)
-    arm_linux_remove_hw_breakpoint1 (&p, TIDGET (ptid), 1);
+  ALL_LWPS (lp)
+    arm_linux_remove_hw_breakpoint1 (&p, ptid_get_lwp (lp->ptid), 1);
 
   return 0;
 }
@@ -1203,33 +1149,38 @@ arm_linux_remove_watchpoint (CORE_ADDR addr, int len, int rw,
 static int
 arm_linux_stopped_data_address (struct target_ops *target, CORE_ADDR *addr_p)
 {
-  struct siginfo *siginfo_p = linux_nat_get_siginfo (inferior_ptid);
-  int slot = siginfo_p->si_errno;
+  siginfo_t siginfo;
+  int slot;
+
+  if (!linux_nat_get_siginfo (inferior_ptid, &siginfo))
+    return 0;
 
   /* This must be a hardware breakpoint.  */
-  if (siginfo_p->si_signo != SIGTRAP
-      || (siginfo_p->si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
+  if (siginfo.si_signo != SIGTRAP
+      || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */)
     return 0;
 
   /* We must be able to set hardware watchpoints.  */
   if (arm_linux_get_hw_watchpoint_count () == 0)
     return 0;
 
+  slot = siginfo.si_errno;
+
   /* If we are in a positive slot then we're looking at a breakpoint and not
      a watchpoint.  */
   if (slot >= 0)
     return 0;
 
-  *addr_p = (CORE_ADDR) (uintptr_t) siginfo_p->si_addr;
+  *addr_p = (CORE_ADDR) (uintptr_t) siginfo.si_addr;
   return 1;
 }
 
 /* Has the target been stopped by hitting a watchpoint?  */
 static int
-arm_linux_stopped_by_watchpoint (void)
+arm_linux_stopped_by_watchpoint (struct target_ops *ops)
 {
   CORE_ADDR addr;
-  return arm_linux_stopped_data_address (&current_target, &addr);
+  return arm_linux_stopped_data_address (ops, &addr);
 }
 
 static int
@@ -1243,9 +1194,9 @@ arm_linux_watchpoint_addr_within_range (struct target_ops *target,
 /* Handle thread creation.  We need to copy the breakpoints and watchpoints
    in the parent thread to the child thread.  */
 static void
-arm_linux_new_thread (ptid_t ptid)
+arm_linux_new_thread (struct lwp_info *lp)
 {
-  int tid = TIDGET (ptid);
+  int tid = ptid_get_lwp (lp->ptid);
   const struct arm_linux_hwbp_cap *info = arm_linux_get_hwbp_cap ();
 
   if (info != NULL)
@@ -1280,7 +1231,7 @@ arm_linux_thread_exit (struct thread_info *tp, int silent)
   if (info != NULL)
     {
       int i;
-      int tid = TIDGET (tp->ptid);
+      int tid = ptid_get_lwp (tp->ptid);
       struct arm_linux_thread_points *t = NULL, *p;
 
       for (i = 0; 
@@ -1311,8 +1262,6 @@ _initialize_arm_linux_nat (void)
 {
   struct target_ops *t;
 
-  os_version = get_linux_version (&os_major, &os_minor, &os_release);
-
   /* Fill in the generic GNU/Linux methods.  */
   t = linux_target ();