Add Python support for hardware breakpoints
authorHannes Domani <ssbssa@yahoo.de>
Sat, 2 Jan 2021 12:51:27 +0000 (13:51 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Thu, 21 Jan 2021 17:55:45 +0000 (18:55 +0100)
This allows the creation of hardware breakpoints in Python with
gdb.Breakpoint(type=gdb.BP_HARDWARE_BREAKPOINT)
And they are included in the sequence returned by gdb.breakpoints().

gdb/ChangeLog:

2021-01-21  Hannes Domani  <ssbssa@yahoo.de>

PR python/19151
* python/py-breakpoint.c (bppy_get_location): Handle
bp_hardware_breakpoint.
(bppy_init): Likewise.
(gdbpy_breakpoint_created): Likewise.

gdb/doc/ChangeLog:

2021-01-21  Hannes Domani  <ssbssa@yahoo.de>

PR python/19151
* python.texi (Breakpoints In Python): Document
gdb.BP_HARDWARE_BREAKPOINT.

gdb/testsuite/ChangeLog:

2021-01-21  Hannes Domani  <ssbssa@yahoo.de>

PR python/19151
* gdb.python/py-breakpoint.exp: Add tests for hardware breakpoints.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/py-breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-breakpoint.exp

index b51bb152105e1d9b61784fb90c619912a53e0a35..468447dd03abd8469e8b9b6491aed3416b44195b 100644 (file)
@@ -1,3 +1,11 @@
+2021-01-21  Hannes Domani  <ssbssa@yahoo.de>
+
+       PR python/19151
+       * python/py-breakpoint.c (bppy_get_location): Handle
+       bp_hardware_breakpoint.
+       (bppy_init): Likewise.
+       (gdbpy_breakpoint_created): Likewise.
+
 2021-01-21  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * arm-tdep.c (arm_debug_printf): Add and use throughout file.
index d718fdda75ee6e11aba2f7b4b7d79bb35c2b9f56..64eb52bd5218e33ef60184f1cd7cf111bb868e2e 100644 (file)
@@ -1,3 +1,9 @@
+2021-01-21  Hannes Domani  <ssbssa@yahoo.de>
+
+       PR python/19151
+       * python.texi (Breakpoints In Python): Document
+       gdb.BP_HARDWARE_BREAKPOINT.
+
 2021-01-01  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.texinfo, refcard.tex: Update copyright year range.
index 0f776f54768b0c623cbb42680c3aa77bb2883295..35568594f5872e59f0bdb89bf112c4a6f7e518fb 100644 (file)
@@ -5402,6 +5402,10 @@ module:
 @item gdb.BP_BREAKPOINT
 Normal code breakpoint.
 
+@vindex BP_HARDWARE_BREAKPOINT
+@item gdb.BP_HARDWARE_BREAKPOINT
+Hardware assisted code breakpoint.
+
 @vindex BP_WATCHPOINT
 @item gdb.BP_WATCHPOINT
 Watchpoint breakpoint.
index 9f6ae96266fac2978457323d2f19e45889f8b765..3fbb1c633ff49ff91d013cb22980df9d78c332bc 100644 (file)
@@ -58,6 +58,7 @@ static struct pybp_code pybp_codes[] =
 {
   { "BP_NONE", bp_none},
   { "BP_BREAKPOINT", bp_breakpoint},
+  { "BP_HARDWARE_BREAKPOINT", bp_hardware_breakpoint},
   { "BP_WATCHPOINT", bp_watchpoint},
   { "BP_HARDWARE_WATCHPOINT", bp_hardware_watchpoint},
   { "BP_READ_WATCHPOINT", bp_read_watchpoint},
@@ -383,7 +384,8 @@ bppy_get_location (PyObject *self, void *closure)
 
   BPPY_REQUIRE_VALID (obj);
 
-  if (obj->bp->type != bp_breakpoint)
+  if (obj->bp->type != bp_breakpoint
+      && obj->bp->type != bp_hardware_breakpoint)
     Py_RETURN_NONE;
 
   const char *str = event_location_to_string (obj->bp->location.get ());
@@ -793,6 +795,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
       switch (type)
        {
        case bp_breakpoint:
+       case bp_hardware_breakpoint:
          {
            event_location_up location;
            symbol_name_match_type func_name_match_type
@@ -834,7 +837,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
            create_breakpoint (python_gdbarch,
                               location.get (), NULL, -1, NULL,
                               0,
-                              temporary_bp, bp_breakpoint,
+                              temporary_bp, type,
                               0,
                               AUTO_BOOLEAN_TRUE,
                               ops,
@@ -1008,6 +1011,7 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
     return;
 
   if (bp->type != bp_breakpoint
+      && bp->type != bp_hardware_breakpoint
       && bp->type != bp_watchpoint
       && bp->type != bp_hardware_watchpoint
       && bp->type != bp_read_watchpoint
index 554d9e0823e1915a37e001caebc76cd97b2857b0..507b985e7a82be4b0c56962b5c47df40b3a72e58 100644 (file)
@@ -1,3 +1,8 @@
+2021-01-21  Hannes Domani  <ssbssa@yahoo.de>
+
+       PR python/19151
+       * gdb.python/py-breakpoint.exp: Add tests for hardware breakpoints.
+
 2021-01-20  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * lib/tuiterm.exp: Rename _cur_x/_cur_y to _cur_col/_cur_row.
index 3c06a89856e0122035b4309ede81f1f42be51f6b..64a70abb1264f187f46738dd116d8e0366ced740 100644 (file)
@@ -252,6 +252,29 @@ proc_with_prefix test_bkpt_invisible { } {
        "Check maint info breakpoints shows invisible breakpoints"
 }
 
+proc_with_prefix test_hardware_breakpoints { } {
+    global srcfile testfile hex decimal
+
+    # Start with a fresh gdb.
+    clean_restart ${testfile}
+
+    if ![runto_main] then {
+       fail "cannot run to main."
+       return 0
+    }
+
+    delete_breakpoints
+
+    gdb_test "python hbp1 = gdb.Breakpoint(\"add\", type=gdb.BP_HARDWARE_BREAKPOINT)" \
+       ".*Hardware assisted breakpoint ($decimal)+ at .*$srcfile, line ($decimal)+\." \
+       "Set hardware breakpoint"
+    gdb_test "python print (gdb.breakpoints()\[0\].type == gdb.BP_HARDWARE_BREAKPOINT)" \
+       "True" "Check hardware breakpoint type"
+    gdb_test "continue" \
+       ".*Breakpoint ($decimal)+, add.*" \
+       "Test hardware breakpoint stop"
+}
+
 proc_with_prefix test_watchpoints { } {
     global srcfile testfile hex decimal
 
@@ -718,6 +741,7 @@ test_bkpt_basic
 test_bkpt_deletion
 test_bkpt_cond_and_cmds
 test_bkpt_invisible
+test_hardware_breakpoints
 test_watchpoints
 test_bkpt_internal
 test_bkpt_eval_funcs