public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/guile: don't try to print location for watchpoints
@ 2021-05-06  9:58 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2021-05-06  9:58 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0618ecf6eb99dce0278102a88f622f28e3ecd837

commit 0618ecf6eb99dce0278102a88f622f28e3ecd837
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Wed May 5 16:52:29 2021 +0100

    gdb/guile: don't try to print location for watchpoints
    
    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.

Diff:
---
 gdb/ChangeLog                              |  5 +++++
 gdb/guile/scm-breakpoint.c                 | 11 ++++++-----
 gdb/testsuite/ChangeLog                    |  5 +++++
 gdb/testsuite/gdb.guile/scm-breakpoint.exp |  5 +++++
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 14b1a3d0c8f..187249db47e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index 25b438b7210..826dfa9b0a3 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -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);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a9671475306..a6050d640fe 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -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
diff --git a/gdb/testsuite/gdb.guile/scm-breakpoint.exp b/gdb/testsuite/gdb.guile/scm-breakpoint.exp
index 9d271739852..56058942e64 100644
--- a/gdb/testsuite/gdb.guile/scm-breakpoint.exp
+++ b/gdb/testsuite/gdb.guile/scm-breakpoint.exp
@@ -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"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-06  9:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06  9:58 [binutils-gdb] gdb/guile: don't try to print location for watchpoints Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).