public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] Pass aarch64_debug_reg_state to functions
Date: Tue, 07 Jul 2015 15:23:00 -0000	[thread overview]
Message-ID: <1436282578-8070-4-git-send-email-yao.qi@linaro.org> (raw)
In-Reply-To: <1436282578-8070-1-git-send-email-yao.qi@linaro.org>

Some functions on handling HW watchpoint in GDB and GDBserver looks the
same except the code getting debug register state from current inferior.
In GDB, we get debug register state like this:

  state = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));

while in GDBserver, we get debug register state like this:

  state = aarch64_get_debug_reg_state ();

This patch is to move two lines above out of some functions, and pass
aarch64_debug_reg_state to these functions, in this way, these functions
are the same, and can be moved to a common place.

gdb:

2015-07-06  Yao Qi  <yao.qi@linaro.org>

	* aarch64-linux-nat.c (aarch64_handle_breakpoint): Add argument
	state and don't call aarch64_get_debug_reg_state.  All callers
	update.
	(aarch64_linux_insert_hw_breakpoint): Call
	aarch64_get_debug_reg_state earlier.
	(aarch64_linux_remove_hw_breakpoint): Likewise.
	(aarch64_handle_aligned_watchpoint): Add argument state and
	don't call aarch64_get_debug_reg_state.  All callers update.
	(aarch64_handle_unaligned_watchpoint): Likewise.
	(aarch64_handle_watchpoint): Add argument state.
	(aarch64_linux_insert_watchpoint): Call aarch64_get_debug_reg_state
	earlier.
	(aarch64_linux_remove_watchpoint): Likewise.

gdb/gdbserver:

2015-07-06  Yao Qi  <yao.qi@linaro.org>

	* linux-aarch64-low.c (aarch64_handle_breakpoint): Add argument state
	and don't aarch64_get_debug_reg_state.  All callers update.
	(aarch64_handle_aligned_watchpoint): Likewise.
	(aarch64_handle_unaligned_watchpoint): Likewise.
	(aarch64_handle_watchpoint): Likewise.
	(aarch64_insert_point): Call aarch64_get_debug_reg_state earlier.
	(aarch64_remove_point): Likewise.
---
 gdb/aarch64-linux-nat.c           | 56 +++++++++++++++++----------------------
 gdb/gdbserver/linux-aarch64-low.c | 43 +++++++++++++++---------------
 2 files changed, 46 insertions(+), 53 deletions(-)

diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index 869edda..ecf402e 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -1164,17 +1164,14 @@ aarch64_dr_state_remove_one_point (struct aarch64_debug_reg_state *state,
 
 static int
 aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr,
-			   int len, int is_insert)
+			   int len, int is_insert,
+			   struct aarch64_debug_reg_state *state)
 {
-  struct aarch64_debug_reg_state *state;
-
   /* The hardware breakpoint on AArch64 should always be 4-byte
      aligned.  */
   if (!aarch64_point_is_aligned (0 /* is_watchpoint */ , addr, len))
     return -1;
 
-  state = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
   if (is_insert)
     return aarch64_dr_state_insert_one_point (state, type, addr, len);
   else
@@ -1193,6 +1190,8 @@ aarch64_linux_insert_hw_breakpoint (struct target_ops *self,
   CORE_ADDR addr = bp_tgt->placed_address = bp_tgt->reqstd_address;
   const int len = 4;
   const enum target_hw_bp_type type = hw_execute;
+  struct aarch64_debug_reg_state *state
+    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
 
   if (show_debug_regs)
     fprintf_unfiltered
@@ -1200,13 +1199,10 @@ aarch64_linux_insert_hw_breakpoint (struct target_ops *self,
        "insert_hw_breakpoint on entry (addr=0x%08lx, len=%d))\n",
        (unsigned long) addr, len);
 
-  ret = aarch64_handle_breakpoint (type, addr, len, 1 /* is_insert */);
+  ret = aarch64_handle_breakpoint (type, addr, len, 1 /* is_insert */, state);
 
   if (show_debug_regs)
     {
-      struct aarch64_debug_reg_state *state
-	= aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
       aarch64_show_debug_reg_state (state,
 				    "insert_hw_breakpoint", addr, len, type);
     }
@@ -1226,19 +1222,18 @@ aarch64_linux_remove_hw_breakpoint (struct target_ops *self,
   CORE_ADDR addr = bp_tgt->placed_address;
   const int len = 4;
   const enum target_hw_bp_type type = hw_execute;
+  struct aarch64_debug_reg_state *state
+    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
 
   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 */);
+  ret = aarch64_handle_breakpoint (type, addr, len, 0 /* is_insert */, state);
 
   if (show_debug_regs)
     {
-      struct aarch64_debug_reg_state *state
-	= aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
       aarch64_show_debug_reg_state (state,
 				    "remove_hw_watchpoint", addr, len, type);
     }
@@ -1251,11 +1246,9 @@ aarch64_linux_remove_hw_breakpoint (struct target_ops *self,
 
 static int
 aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr,
-				   int len, int is_insert)
+				   int len, int is_insert,
+				   struct aarch64_debug_reg_state *state)
 {
-  struct aarch64_debug_reg_state *state
-    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
   if (is_insert)
     return aarch64_dr_state_insert_one_point (state, type, addr, len);
   else
@@ -1271,11 +1264,9 @@ aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr,
 
 static int
 aarch64_handle_unaligned_watchpoint (int type, CORE_ADDR addr, int len,
-				     int is_insert)
+				     int is_insert,
+				     struct aarch64_debug_reg_state *state)
 {
-  struct aarch64_debug_reg_state *state
-    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
   while (len > 0)
     {
       CORE_ADDR aligned_addr;
@@ -1308,12 +1299,15 @@ aarch64_handle_unaligned_watchpoint (int type, CORE_ADDR addr, int len,
 /* Implements insertion and removal of a single watchpoint.  */
 
 static int
-aarch64_handle_watchpoint (int type, CORE_ADDR addr, int len, int is_insert)
+aarch64_handle_watchpoint (int type, CORE_ADDR addr, int len, int is_insert,
+			   struct aarch64_debug_reg_state *state)
 {
   if (aarch64_point_is_aligned (1 /* is_watchpoint */ , addr, len))
-    return aarch64_handle_aligned_watchpoint (type, addr, len, is_insert);
+    return aarch64_handle_aligned_watchpoint (type, addr, len, is_insert,
+					      state);
   else
-    return aarch64_handle_unaligned_watchpoint (type, addr, len, is_insert);
+    return aarch64_handle_unaligned_watchpoint (type, addr, len, is_insert,
+						state);
 }
 
 /* Implement the "to_insert_watchpoint" target_ops method.
@@ -1328,6 +1322,8 @@ aarch64_linux_insert_watchpoint (struct target_ops *self,
 				 struct expression *cond)
 {
   int ret;
+  struct aarch64_debug_reg_state *state
+    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
 
   if (show_debug_regs)
     fprintf_unfiltered (gdb_stdlog,
@@ -1336,13 +1332,10 @@ aarch64_linux_insert_watchpoint (struct target_ops *self,
 
   gdb_assert (type != hw_execute);
 
-  ret = aarch64_handle_watchpoint (type, addr, len, 1 /* is_insert */);
+  ret = aarch64_handle_watchpoint (type, addr, len, 1 /* is_insert */, state);
 
   if (show_debug_regs)
     {
-      struct aarch64_debug_reg_state *state
-	= aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
       aarch64_show_debug_reg_state (state,
 				    "insert_watchpoint", addr, len, type);
     }
@@ -1361,6 +1354,8 @@ aarch64_linux_remove_watchpoint (struct target_ops *self,
 				 struct expression *cond)
 {
   int ret;
+  struct aarch64_debug_reg_state *state
+    = aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
 
   if (show_debug_regs)
     fprintf_unfiltered (gdb_stdlog,
@@ -1369,13 +1364,10 @@ aarch64_linux_remove_watchpoint (struct target_ops *self,
 
   gdb_assert (type != hw_execute);
 
-  ret = aarch64_handle_watchpoint (type, addr, len, 0 /* is_insert */);
+  ret = aarch64_handle_watchpoint (type, addr, len, 0 /* is_insert */, state);
 
   if (show_debug_regs)
     {
-      struct aarch64_debug_reg_state *state
-	= aarch64_get_debug_reg_state (ptid_get_pid (inferior_ptid));
-
       aarch64_show_debug_reg_state (state,
 				    "remove_watchpoint", addr, len, type);
     }
diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c
index 6c6b8d9..1782aff 100644
--- a/gdb/gdbserver/linux-aarch64-low.c
+++ b/gdb/gdbserver/linux-aarch64-low.c
@@ -859,17 +859,14 @@ aarch64_dr_state_remove_one_point (struct aarch64_debug_reg_state *state,
 
 static int
 aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr,
-			   int len, int is_insert)
+			   int len, int is_insert,
+			   struct aarch64_debug_reg_state *state)
 {
-  struct aarch64_debug_reg_state *state;
-
   /* The hardware breakpoint on AArch64 should always be 4-byte
      aligned.  */
   if (!aarch64_point_is_aligned (0 /* is_watchpoint */ , addr, len))
     return -1;
 
-  state = aarch64_get_debug_reg_state ();
-
   if (is_insert)
     return aarch64_dr_state_insert_one_point (state, type, addr, len);
   else
@@ -881,12 +878,9 @@ aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr,
 
 static int
 aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type,
-				   CORE_ADDR addr, int len, int is_insert)
+				   CORE_ADDR addr, int len, int is_insert,
+				   struct aarch64_debug_reg_state *state)
 {
-  struct aarch64_debug_reg_state *state;
-
-  state = aarch64_get_debug_reg_state ();
-
   if (is_insert)
     return aarch64_dr_state_insert_one_point (state, type, addr, len);
   else
@@ -902,11 +896,9 @@ aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type,
 
 static int
 aarch64_handle_unaligned_watchpoint (enum target_hw_bp_type type,
-				     CORE_ADDR addr, int len, int is_insert)
+				     CORE_ADDR addr, int len, int is_insert,
+				     struct aarch64_debug_reg_state *state)
 {
-  struct aarch64_debug_reg_state *state
-    = aarch64_get_debug_reg_state ();
-
   while (len > 0)
     {
       CORE_ADDR aligned_addr;
@@ -939,12 +931,15 @@ aarch64_handle_unaligned_watchpoint (enum target_hw_bp_type type,
 
 static int
 aarch64_handle_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr,
-			   int len, int is_insert)
+			   int len, int is_insert,
+			   struct aarch64_debug_reg_state *state)
 {
   if (aarch64_point_is_aligned (1 /* is_watchpoint */ , addr, len))
-    return aarch64_handle_aligned_watchpoint (type, addr, len, is_insert);
+    return aarch64_handle_aligned_watchpoint (type, addr, len, is_insert,
+					      state);
   else
-    return aarch64_handle_unaligned_watchpoint (type, addr, len, is_insert);
+    return aarch64_handle_unaligned_watchpoint (type, addr, len, is_insert,
+						state);
 }
 
 static int
@@ -977,6 +972,7 @@ aarch64_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
 {
   int ret;
   enum target_hw_bp_type targ_type;
+  struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state ();
 
   if (show_debug_regs)
     fprintf (stderr, "insert_point on entry (addr=0x%08lx, len=%d)\n",
@@ -987,10 +983,12 @@ aarch64_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
 
   if (targ_type != hw_execute)
     ret =
-      aarch64_handle_watchpoint (targ_type, addr, len, 1 /* is_insert */);
+      aarch64_handle_watchpoint (targ_type, addr, len, 1 /* is_insert */,
+				 state);
   else
     ret =
-      aarch64_handle_breakpoint (targ_type, addr, len, 1 /* is_insert */);
+      aarch64_handle_breakpoint (targ_type, addr, len, 1 /* is_insert */,
+				 state);
 
   if (show_debug_regs)
     aarch64_show_debug_reg_state (aarch64_get_debug_reg_state (),
@@ -1013,6 +1011,7 @@ aarch64_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
 {
   int ret;
   enum target_hw_bp_type targ_type;
+  struct aarch64_debug_reg_state *state = aarch64_get_debug_reg_state ();
 
   if (show_debug_regs)
     fprintf (stderr, "remove_point on entry (addr=0x%08lx, len=%d)\n",
@@ -1024,10 +1023,12 @@ aarch64_remove_point (enum raw_bkpt_type type, CORE_ADDR addr,
   /* Set up state pointers.  */
   if (targ_type != hw_execute)
     ret =
-      aarch64_handle_watchpoint (targ_type, addr, len, 0 /* is_insert */);
+      aarch64_handle_watchpoint (targ_type, addr, len, 0 /* is_insert */,
+				 state);
   else
     ret =
-      aarch64_handle_breakpoint (targ_type, addr, len, 0 /* is_insert */);
+      aarch64_handle_breakpoint (targ_type, addr, len, 0 /* is_insert */,
+				 state);
 
   if (show_debug_regs)
     aarch64_show_debug_reg_state (aarch64_get_debug_reg_state (),
-- 
1.9.1

  reply	other threads:[~2015-07-07 15:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07 15:23 [PATCH 0/4] Move common aarch64 HW breakpoint/watchpoint code to nat/ Yao Qi
2015-07-07 15:23 ` Yao Qi [this message]
2015-07-07 15:23 ` [PATCH 4/4] " Yao Qi
2015-07-07 15:23 ` [PATCH 2/4] Use debug_printf to print debug message Yao Qi
2015-07-14 14:02   ` Gary Benson
2015-07-07 15:23 ` [PATCH 1/4] int -> enum target_hw_bp_type in aarch64-linux-nat.c Yao Qi
2015-07-14 14:05 ` [PATCH 0/4] Move common aarch64 HW breakpoint/watchpoint code to nat/ Gary Benson
2015-07-17 13:36   ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436282578-8070-4-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).