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

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

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed

Commit Message

Bouhaouel, Mohamed Nov. 14, 2023, 1:35 p.m. UTC
  Add a new function 'bptype_to_target_hw_bp_type' to perform
the translation from 'bptype' to 'target_hw_bp_type'.

Reviewed-By: Guinevere Larsen <blarsen@redhat.com>
---
 gdb/breakpoint.c | 20 ++++++++++++++++++++
 gdb/breakpoint.h |  3 +++
 2 files changed, 23 insertions(+)
  

Comments

Tom Tromey Nov. 14, 2023, 2:37 p.m. UTC | #1
>>>>> Mohamed Bouhaouel <mohamed.bouhaouel@intel.com> writes:

> Add a new function 'bptype_to_target_hw_bp_type' to perform
> the translation from 'bptype' to 'target_hw_bp_type'.

Thank you.

> +target_hw_bp_type
> +bptype_to_target_hw_bp_type (bptype type)
> +{

> +    default:
> +      error (_ ("Bad breakpoint type: bptype %d."), type);

Can this ever be reached?  If not it should be gdb_assert_not_reached.
If so then it should have a better error message -- this one won't make
sense to users.

> +/* Translate BPTYPE to TARGET_HW_BP_TYPE.  */
> +
> +extern target_hw_bp_type bptype_to_target_hw_bp_type (bptype type);
>  #endif /* !defined (BREAKPOINT_H) */

Newline before #endif

Tom
  
Bouhaouel, Mohamed Nov. 15, 2023, 5:44 p.m. UTC | #2
Hi,

Thanks for the feedback.

> > +target_hw_bp_type
> > +bptype_to_target_hw_bp_type (bptype type)
> > +{
> 
> > +    default:
> > +      error (_ ("Bad breakpoint type: bptype %d."), type);
> 
> Can this ever be reached?  If not it should be gdb_assert_not_reached.
> If so then it should have a better error message -- this one won't make
> sense to users.

It can be reached by mistake, e.g. if someone passes a wrong btype to the function.
I find using "gdb_assert_not_reached" is more suitable in this case. I will change it
in the next patch update.

> > +extern target_hw_bp_type bptype_to_target_hw_bp_type (bptype type);
> >  #endif /* !defined (BREAKPOINT_H) */
> 
> Newline before #endif

Will be address in the next update.

Regards,
Mohamed
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fe09dbcbeee..13eaff79789 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9827,6 +9827,26 @@  watchpoint::~watchpoint ()
   bpt->related_breakpoint = this->related_breakpoint;
 }
 
+/* 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 e75efc90495..cc9a1ebc184 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -2029,4 +2029,7 @@  extern void enable_disable_bp_location (bp_location *loc, bool enable);
 
 extern void notify_breakpoint_modified (breakpoint *b);
 
+/* Translate BPTYPE to TARGET_HW_BP_TYPE.  */
+
+extern target_hw_bp_type bptype_to_target_hw_bp_type (bptype type);
 #endif /* !defined (BREAKPOINT_H) */