gdb/guile: don't try to print location for watchpoints
authorAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 5 May 2021 15:52:29 +0000 (16:52 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 6 May 2021 09:44:29 +0000 (10:44 +0100)
Currently, using the guile API, if a user tries to print a breakpoint
object that represents a watchpoint, then GDB will crash.  For
example:

  (gdb) guile (use-modules (gdb))
  (gdb) guile (define wp1 (make-breakpoint "some_variable" #:type BP_WATCHPOINT #:wp-class WP_WRITE))
  (gdb) guile (register-breakpoint! wp1)
  (gdb) guile (display wp1) (newline)
  Aborted (core dumped)

This turns out to be because GDB calls event_location_to_string on the
breakpoints location, and watchpoint breakpoints don't have a
location.

This commit resolves the crash by just skipping the printing of the
location if the breakpoint doesn't have one.

Potentially, we could improve on this by printing details about what
the watchpoint is watching, however, I'm considering this a possible
future enhancement, this commit focuses just on having GDB not crash.

gdb/ChangeLog:

* guile/scm-breakpoint.c (bpscm_print_breakpoint_smob): Only print
breakpoint locations when the breakpoint actually has a location.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-breakpoint.exp (test_watchpoints): Print the
watchpoint object before and after registering it with GDB.

gdb/ChangeLog
gdb/guile/scm-breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.guile/scm-breakpoint.exp

index 14b1a3d0c8f99bf9fda202051d6cf75797a50eb4..187249db47eab7aea643ab5f1df3e8418a883d23 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-06  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * guile/scm-breakpoint.c (bpscm_print_breakpoint_smob): Only print
+       breakpoint locations when the breakpoint actually has a location.
+
 2021-05-06  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        * mi/mi-cmd-break.c (mi_cmd_break_condition): New function.
index 25b438b72103bd0e3caa0d7848d26eb1989fa959..826dfa9b0a38fe3024585fb5ced4ed0a26515bd4 100644 (file)
@@ -174,8 +174,6 @@ bpscm_print_breakpoint_smob (SCM self, SCM port, scm_print_state *pstate)
   /* Careful, the breakpoint may be invalid.  */
   if (b != NULL)
     {
-      const char *str;
-
       gdbscm_printf (port, " %s %s %s",
                     bpscm_type_to_string (b->type),
                     bpscm_enable_state_to_string (b->enable_state),
@@ -184,9 +182,12 @@ bpscm_print_breakpoint_smob (SCM self, SCM port, scm_print_state *pstate)
       gdbscm_printf (port, " hit:%d", b->hit_count);
       gdbscm_printf (port, " ignore:%d", b->ignore_count);
 
-      str = event_location_to_string (b->location.get ());
-      if (str != NULL)
-       gdbscm_printf (port, " @%s", str);
+      if (b->location != nullptr)
+       {
+         const char *str = event_location_to_string (b->location.get ());
+         if (str != nullptr)
+           gdbscm_printf (port, " @%s", str);
+       }
     }
 
   scm_puts (">", port);
index a9671475306b512ce58a2b32e55503b429a2fd6c..a6050d640fedbcbc581d58e4003ed3d9ef4f973d 100644 (file)
@@ -1,3 +1,8 @@
+2021-05-06  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.guile/scm-breakpoint.exp (test_watchpoints): Print the
+       watchpoint object before and after registering it with GDB.
+
 2021-05-06  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.guile/scm-breakpoint.exp (test_bkpt_basic): Convert to
index 9d271739852d9c852e072c4d0d90e52ec541af73..56058942e64637f1d2d3aa5690d13ba3a54be2f8 100644 (file)
@@ -248,8 +248,13 @@ proc_with_prefix test_watchpoints { } {
 
     gdb_scm_test_silent_cmd  "guile (define wp1 (make-breakpoint \"result\" #:type BP_WATCHPOINT #:wp-class WP_WRITE))" \
        "create watchpoint"
+    gdb_test "guile (display wp1) (newline)" "#<gdb:breakpoint #-1>" \
+       "print watchpoint before registering"
     gdb_scm_test_silent_cmd "guile (register-breakpoint! wp1)" \
        "register wp1"
+    gdb_test "guile (display wp1) (newline)" \
+       "#<gdb:breakpoint #${decimal} BP_(?:HARDWARE_)?WATCHPOINT enabled noisy hit:0 ignore:0>" \
+       "print watchpoint after registering"
     gdb_test "continue" \
        ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
        "test watchpoint write"
This page took 0.040763 seconds and 4 git commands to generate.