[2/3] gdb, breakpoint: add a breakpoint type converter

Message ID 20230328115449.6526-3-mohamed.bouhaouel@intel.com
State New
Headers
Series Check for zpoint support when handling watchpoints |

Commit Message

Bouhaouel, Mohamed March 28, 2023, 11:54 a.m. UTC
  Add a new function 'bptype_to_target_hw_bp_type' to perform
the translation from 'bptype' to 'target_hw_bp_type'.

Signed-off-by: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>
---
 gdb/breakpoint.c | 20 ++++++++++++++++++++
 gdb/breakpoint.h |  3 +++
 2 files changed, 23 insertions(+)
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 7228acfd8fe..e71cf7639d9 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9581,6 +9581,26 @@  break_range_command (const char *arg, int from_tty)
   install_breakpoint (false, std::move (br), true);
 }
 
+/* See breakpoint.h.  */
+
+target_hw_bp_type
+bptype_to_target_hw_bp_type (bptype type)
+{
+  switch (type)
+    {
+    case bp_hardware_watchpoint:
+      return hw_write;
+    case bp_read_watchpoint:
+      return hw_read;
+    case bp_access_watchpoint:
+      return hw_access;
+    case bp_hardware_breakpoint:
+      return hw_execute;
+    default:
+      error (_ ("Bad breakpoint type: bptype %d."), type);
+    }
+}
+
 /*  Return non-zero if EXP is verified as constant.  Returned zero
     means EXP is variable.  Also the constant detection may fail for
     some constant expressions and in such case still falsely return
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 7c5cf3f2bef..12fa5c96e08 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1946,4 +1946,7 @@  extern void describe_other_breakpoints (struct gdbarch *,
 
 extern void enable_disable_bp_location (bp_location *loc, bool enable);
 
+/* Translate BPTYPE to TARGET_HW_BP_TYPE.  */
+
+extern target_hw_bp_type bptype_to_target_hw_bp_type (bptype type);
 #endif /* !defined (BREAKPOINT_H) */