Introduce show_debug_regs
[deliverable/binutils-gdb.git] / gdb / aarch64-linux-nat.c
index 7d76833509c63b9214cd64f20f517a7615534e79..1c1832f0b6f0c322bf7d028365bc5db8f9032235 100644 (file)
@@ -1,6 +1,6 @@
 /* Native-dependent code for GNU/Linux AArch64.
 
-   Copyright (C) 2011-2013 Free Software Foundation, Inc.
+   Copyright (C) 2011-2014 Free Software Foundation, Inc.
    Contributed by ARM Ltd.
 
    This file is part of GDB.
@@ -33,6 +33,7 @@
 
 #include <sys/ptrace.h>
 #include <sys/utsname.h>
+#include <asm/ptrace.h>
 
 #include "gregset.h"
 
@@ -118,10 +119,6 @@ get_thread_id (ptid_t ptid)
 static int aarch64_num_bp_regs;
 static int aarch64_num_wp_regs;
 
-/* Debugging of hardware breakpoint/watchpoint support.  */
-
-static int debug_hw_points;
-
 /* Each bit of a variable of this type is used to indicate whether a
    hardware breakpoint or watchpoint setting has been changed since
    the last update.
@@ -143,7 +140,7 @@ static int debug_hw_points;
    ptrace calls to the kernel, i.e. avoid asking the kernel to write
    to the debug registers with unchanged values.  */
 
-typedef unsigned LONGEST dr_changed_t;
+typedef ULONGEST dr_changed_t;
 
 /* Set each of the lower M bits of X to 1; assert X is wide enough.  */
 
@@ -362,7 +359,7 @@ debug_reg_change_callback (struct lwp_info *lwp, void *ptr)
   if (info == NULL)
     info = lwp->arch_private = XCNEW (struct arch_lwp_info);
 
-  if (debug_hw_points)
+  if (show_debug_regs)
     {
       fprintf_unfiltered (gdb_stdlog,
                          "debug_reg_change_callback: \n\tOn entry:\n");
@@ -391,7 +388,7 @@ debug_reg_change_callback (struct lwp_info *lwp, void *ptr)
   if (!lwp->stopped)
     linux_stop_lwp (lwp);
 
-  if (debug_hw_points)
+  if (show_debug_regs)
     {
       fprintf_unfiltered (gdb_stdlog,
                          "\tOn exit:\n\tpid%d, dr_changed_bp=0x%s, "
@@ -615,14 +612,9 @@ void
 fill_gregset (const struct regcache *regcache,
              gdb_gregset_t *gregsetp, int regno)
 {
-  gdb_byte *gregs_buf = (gdb_byte *) gregsetp;
-  int i;
-
-  for (i = AARCH64_X0_REGNUM; i <= AARCH64_CPSR_REGNUM; i++)
-    if (regno == -1 || regno == i)
-      regcache_raw_collect (regcache, i,
-                           gregs_buf + X_REGISTER_SIZE
-                           * (i - AARCH64_X0_REGNUM));
+  regcache_collect_regset (&aarch64_linux_gregset, regcache,
+                          regno, (gdb_byte *) gregsetp,
+                          AARCH64_LINUX_SIZEOF_GREGSET);
 }
 
 /* Fill GDB's register array with the general-purpose register values
@@ -631,7 +623,9 @@ fill_gregset (const struct regcache *regcache,
 void
 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
 {
-  aarch64_linux_supply_gregset (regcache, (const gdb_byte *) gregsetp);
+  regcache_supply_regset (&aarch64_linux_gregset, regcache, -1,
+                         (const gdb_byte *) gregsetp,
+                         AARCH64_LINUX_SIZEOF_GREGSET);
 }
 
 /* Fill register REGNO (if it is a floating-point register) in
@@ -642,22 +636,9 @@ void
 fill_fpregset (const struct regcache *regcache,
               gdb_fpregset_t *fpregsetp, int regno)
 {
-  gdb_byte *fpregs_buf = (gdb_byte *) fpregsetp;
-  int i;
-
-  for (i = AARCH64_V0_REGNUM; i <= AARCH64_V31_REGNUM; i++)
-    if (regno == -1 || regno == i)
-      regcache_raw_collect (regcache, i,
-                           fpregs_buf + V_REGISTER_SIZE
-                           * (i - AARCH64_V0_REGNUM));
-
-  if (regno == -1 || regno == AARCH64_FPSR_REGNUM)
-    regcache_raw_collect (regcache, AARCH64_FPSR_REGNUM,
-                         fpregs_buf + V_REGISTER_SIZE * 32);
-
-  if (regno == -1 || regno == AARCH64_FPCR_REGNUM)
-    regcache_raw_collect (regcache, AARCH64_FPCR_REGNUM,
-                         fpregs_buf + V_REGISTER_SIZE * 32 + 4);
+  regcache_collect_regset (&aarch64_linux_fpregset, regcache,
+                          regno, (gdb_byte *) fpregsetp,
+                          AARCH64_LINUX_SIZEOF_FPREGSET);
 }
 
 /* Fill GDB's register array with the floating-point register values
@@ -666,7 +647,9 @@ fill_fpregset (const struct regcache *regcache,
 void
 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
 {
-  aarch64_linux_supply_fpregset (regcache, (const gdb_byte *) fpregsetp);
+  regcache_supply_regset (&aarch64_linux_fpregset, regcache, -1,
+                         (const gdb_byte *) fpregsetp,
+                         AARCH64_LINUX_SIZEOF_FPREGSET);
 }
 
 /* Called when resuming a thread.
@@ -690,7 +673,7 @@ aarch64_linux_prepare_to_resume (struct lwp_info *lwp)
       struct aarch64_debug_reg_state *state
        = aarch64_get_debug_reg_state (ptid_get_pid (lwp->ptid));
 
-      if (debug_hw_points)
+      if (show_debug_regs)
        fprintf_unfiltered (gdb_stdlog, "prepare_to_resume thread %d\n", tid);
 
       /* Watchpoints.  */
@@ -828,16 +811,18 @@ aarch64_linux_get_debug_reg_capacity (void)
     }
 }
 
-static void (*super_post_startup_inferior) (ptid_t ptid);
+static void (*super_post_startup_inferior) (struct target_ops *self,
+                                           ptid_t ptid);
 
 /* Implement the "to_post_startup_inferior" target_ops method.  */
 
 static void
-aarch64_linux_child_post_startup_inferior (ptid_t ptid)
+aarch64_linux_child_post_startup_inferior (struct target_ops *self,
+                                          ptid_t ptid)
 {
   aarch64_forget_process (ptid_get_pid (ptid));
   aarch64_linux_get_debug_reg_capacity ();
-  super_post_startup_inferior (ptid);
+  super_post_startup_inferior (self, ptid);
 }
 
 /* Implement the "to_read_description" target_ops method.  */
@@ -941,7 +926,8 @@ aarch64_align_watchpoint (CORE_ADDR addr, int len, CORE_ADDR *aligned_addr_p,
    sharing implemented via reference counts.  */
 
 static int
-aarch64_linux_can_use_hw_breakpoint (int type, int cnt, int othertype)
+aarch64_linux_can_use_hw_breakpoint (struct target_ops *self,
+                                    int type, int cnt, int othertype)
 {
   return 1;
 }
@@ -1201,7 +1187,8 @@ aarch64_handle_breakpoint (int type, CORE_ADDR addr, int len, int is_insert)
    Return 0 on success, -1 on failure.  */
 
 static int
-aarch64_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
+aarch64_linux_insert_hw_breakpoint (struct target_ops *self,
+                                   struct gdbarch *gdbarch,
                                    struct bp_target_info *bp_tgt)
 {
   int ret;
@@ -1209,7 +1196,7 @@ aarch64_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
   const int len = 4;
   const int type = hw_execute;
 
-  if (debug_hw_points)
+  if (show_debug_regs)
     fprintf_unfiltered
       (gdb_stdlog,
        "insert_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
@@ -1217,7 +1204,7 @@ aarch64_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
 
   ret = aarch64_handle_breakpoint (type, addr, len, 1 /* is_insert */);
 
-  if (debug_hw_points > 1)
+  if (show_debug_regs)
     {
       struct aarch64_debug_reg_state *state
        = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -1233,7 +1220,8 @@ aarch64_linux_insert_hw_breakpoint (struct gdbarch *gdbarch,
    Return 0 on success, -1 on failure.  */
 
 static int
-aarch64_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
+aarch64_linux_remove_hw_breakpoint (struct target_ops *self,
+                                   struct gdbarch *gdbarch,
                                    struct bp_target_info *bp_tgt)
 {
   int ret;
@@ -1241,14 +1229,14 @@ aarch64_linux_remove_hw_breakpoint (struct gdbarch *gdbarch,
   const int len = 4;
   const int type = hw_execute;
 
-  if (debug_hw_points)
+  if (show_debug_regs)
     fprintf_unfiltered
       (gdb_stdlog, "remove_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
        (unsigned long) addr, len);
 
   ret = aarch64_handle_breakpoint (type, addr, len, 0 /* is_insert */);
 
-  if (debug_hw_points > 1)
+  if (show_debug_regs)
     {
       struct aarch64_debug_reg_state *state
        = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -1305,7 +1293,7 @@ aarch64_handle_unaligned_watchpoint (int type, CORE_ADDR addr, int len,
        ret = aarch64_dr_state_remove_one_point (state, type, aligned_addr,
                                                 aligned_len);
 
-      if (debug_hw_points)
+      if (show_debug_regs)
        fprintf_unfiltered (gdb_stdlog,
 "handle_unaligned_watchpoint: is_insert: %d\n"
 "                             aligned_addr: 0x%08lx, aligned_len: %d\n"
@@ -1337,12 +1325,13 @@ aarch64_handle_watchpoint (int type, CORE_ADDR addr, int len, int is_insert)
    of the type TYPE.  Return 0 on success, -1 on failure.  */
 
 static int
-aarch64_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
+aarch64_linux_insert_watchpoint (struct target_ops *self,
+                                CORE_ADDR addr, int len, int type,
                                 struct expression *cond)
 {
   int ret;
 
-  if (debug_hw_points)
+  if (show_debug_regs)
     fprintf_unfiltered (gdb_stdlog,
                        "insert_watchpoint on entry (addr=0x%08lx, len=%d)\n",
                        (unsigned long) addr, len);
@@ -1351,7 +1340,7 @@ aarch64_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
 
   ret = aarch64_handle_watchpoint (type, addr, len, 1 /* is_insert */);
 
-  if (debug_hw_points > 1)
+  if (show_debug_regs)
     {
       struct aarch64_debug_reg_state *state
        = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -1369,12 +1358,13 @@ aarch64_linux_insert_watchpoint (CORE_ADDR addr, int len, int type,
    type TYPE.  Return 0 on success, -1 on failure.  */
 
 static int
-aarch64_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
+aarch64_linux_remove_watchpoint (struct target_ops *self,
+                                CORE_ADDR addr, int len, int type,
                                 struct expression *cond)
 {
   int ret;
 
-  if (debug_hw_points)
+  if (show_debug_regs)
     fprintf_unfiltered (gdb_stdlog,
                        "remove_watchpoint on entry (addr=0x%08lx, len=%d)\n",
                        (unsigned long) addr, len);
@@ -1383,7 +1373,7 @@ aarch64_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
 
   ret = aarch64_handle_watchpoint (type, addr, len, 0 /* is_insert */);
 
-  if (debug_hw_points > 1)
+  if (show_debug_regs)
     {
       struct aarch64_debug_reg_state *state
        = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
@@ -1398,7 +1388,8 @@ aarch64_linux_remove_watchpoint (CORE_ADDR addr, int len, int type,
 /* Implement the "to_region_ok_for_hw_watchpoint" target_ops method.  */
 
 static int
-aarch64_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
+aarch64_linux_region_ok_for_hw_watchpoint (struct target_ops *self,
+                                          CORE_ADDR addr, int len)
 {
   CORE_ADDR aligned_addr;
 
@@ -1476,11 +1467,11 @@ aarch64_linux_stopped_data_address (struct target_ops *target,
 /* Implement the "to_stopped_by_watchpoint" target_ops method.  */
 
 static int
-aarch64_linux_stopped_by_watchpoint (void)
+aarch64_linux_stopped_by_watchpoint (struct target_ops *ops)
 {
   CORE_ADDR addr;
 
-  return aarch64_linux_stopped_data_address (&current_target, &addr);
+  return aarch64_linux_stopped_data_address (ops, &addr);
 }
 
 /* Implement the "to_watchpoint_addr_within_range" target_ops method.  */
@@ -1501,7 +1492,7 @@ add_show_debug_regs_command (void)
   /* A maintenance command to enable printing the internal DRi mirror
      variables.  */
   add_setshow_boolean_cmd ("show-debug-regs", class_maintenance,
-                          &debug_hw_points, _("\
+                          &show_debug_regs, _("\
 Set whether to show variables that mirror the AArch64 debug registers."), _("\
 Show whether to show variables that mirror the AArch64 debug registers."), _("\
 Use \"on\" to enable, \"off\" to disable.\n\
This page took 0.030553 seconds and 4 git commands to generate.