[3/4] gdb: LoongArch: Adjust loongarch_stopped_data_address()

Message ID 20250106102123.5694-4-lihui@loongson.cn
State New
Headers
Series gdbserver: LoongArch: Add hardware watchpoint and breakpoint support |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Hui Li Jan. 6, 2025, 10:21 a.m. UTC
  loongarch_stopped_data_address() is a common function and will be used by
gdb and gdbserver, so move its definition from gdb/loongarch-linux-nat.c
to gdb/nat/loongarch-hw-point.c. This is preparation for later gdbserver
patch on LoongArch and is no effect for the current code.

Signed-off-by: Hui Li <lihui@loongson.cn>
---
 gdb/loongarch-linux-nat.c    | 27 ---------------------------
 gdb/nat/loongarch-hw-point.c | 24 ++++++++++++++++++++++++
 gdb/nat/loongarch-hw-point.h |  8 ++++++++
 3 files changed, 32 insertions(+), 27 deletions(-)
  

Patch

diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c
index 07359924b0e..bef88ca0632 100644
--- a/gdb/loongarch-linux-nat.c
+++ b/gdb/loongarch-linux-nat.c
@@ -470,33 +470,6 @@  fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregset,
 				     sizeof (gdb_fpregset_t));
 }
 
-/* Helper for the "stopped_data_address" target method.  Returns TRUE
-   if a hardware watchpoint trap at ADDR_TRAP matches a set watchpoint.
-   The address of the matched watchpoint is returned in *ADDR_P.  */
-
-static bool
-loongarch_stopped_data_address (const struct loongarch_debug_reg_state *state,
-			      CORE_ADDR addr_trap, CORE_ADDR *addr_p)
-{
-
-  int i;
-
-  for (i = loongarch_num_wp_regs - 1; i >= 0; --i)
-    {
-      const CORE_ADDR addr_watch = state->dr_addr_wp[i];
-
-      if (state->dr_ref_count_wp[i]
-	  && DR_CONTROL_ENABLED (state->dr_ctrl_wp[i])
-	  && addr_trap == addr_watch)
-	{
-	  *addr_p = addr_watch;
-	  return true;
-	}
-    }
-  return false;
-}
-
-
 /* Returns the number of hardware watchpoints of type TYPE that we can
    set.  Value is positive if we can set CNT watchpoints, zero if
    setting watchpoints of type TYPE is not supported, and negative if
diff --git a/gdb/nat/loongarch-hw-point.c b/gdb/nat/loongarch-hw-point.c
index cf5ddb68d78..7306d4c71c1 100644
--- a/gdb/nat/loongarch-hw-point.c
+++ b/gdb/nat/loongarch-hw-point.c
@@ -317,3 +317,27 @@  loongarch_region_ok_for_watchpoint (CORE_ADDR addr, int len)
 
   return 1;
 }
+
+/* See nat/loongarch-hw-point.h*/
+
+bool
+loongarch_stopped_data_address (const struct loongarch_debug_reg_state *state,
+				CORE_ADDR addr_trap, CORE_ADDR *addr_p)
+{
+  int i;
+
+  for (i = loongarch_num_wp_regs - 1; i >= 0; --i)
+    {
+      const CORE_ADDR addr_watch = state->dr_addr_wp[i];
+
+      if (state->dr_ref_count_wp[i]
+	  && DR_CONTROL_ENABLED (state->dr_ctrl_wp[i])
+	  && addr_trap == addr_watch)
+	{
+	  *addr_p = addr_watch;
+	  return true;
+	}
+    }
+
+  return false;
+}
diff --git a/gdb/nat/loongarch-hw-point.h b/gdb/nat/loongarch-hw-point.h
index 799df89b428..3098752043a 100644
--- a/gdb/nat/loongarch-hw-point.h
+++ b/gdb/nat/loongarch-hw-point.h
@@ -100,4 +100,12 @@  void loongarch_show_debug_reg_state (struct loongarch_debug_reg_state *state,
 
 int loongarch_region_ok_for_watchpoint (CORE_ADDR addr, int len);
 
+/* Helper for the "stopped_data_address/low_stopped_data_address" target
+   method.  Returns TRUE if a hardware watchpoint trap at ADDR_TRAP matches
+   a set watchpoint.  The address of the matched watchpoint is returned in
+   *ADDR_P.  */
+
+bool loongarch_stopped_data_address (const struct loongarch_debug_reg_state *state,
+				     CORE_ADDR addr_trap, CORE_ADDR *addr_p);
+
 #endif /* GDB_NAT_LOONGARCH_HW_POINT_H */