]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/guile: improve the errors when creating breakpoints
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 10 May 2021 08:53:52 +0000 (09:53 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 25 Jun 2021 17:22:03 +0000 (18:22 +0100)
When creating a breakpoint using the guile API, if an invalid
breakpoint type number was used then the error would report the wrong
argument position, like this:

  (gdb) guile (define wp2 (make-breakpoint "result" #:wp-class WP_WRITE #:type 999))
  ERROR: In procedure make-breakpoint:
  ERROR: In procedure gdbscm_make_breakpoint: Out of range: invalid breakpoint type in position 3: 999
  Error while executing Scheme code.
  (gdb)

The 'position 3' here is actually pointing at WP_WRITE, when it should
say 'position 5' and point to the 999.  This commit fixes this.

However, you also get errors like this:

  (gdb) guile (define wp2 (make-breakpoint "result" #:wp-class WP_WRITE #:type BP_NONE))
  ERROR: In procedure make-breakpoint:
  ERROR: In procedure gdbscm_make_breakpoint: Out of range: invalid breakpoint type in position 3: 0
  Error while executing Scheme code.

The BP_NONE is a valid breakpoint type, it's just not valid for
creating breakpoints through the 'make-breakpoint' API.  The use of
'0' in the error message (which is the value of BP_NONE) is not
great.  This commit changes the error in this case to:

  (gdb) guile (define wp2 (make-breakpoint "result" #:wp-class WP_WRITE #:type BP_NONE))
  ERROR: In procedure make-breakpoint:
  ERROR: In procedure gdbscm_make_breakpoint: unsupported breakpoint type in position 5: "BP_NONE"
  Error while executing Scheme code.

Which seems better; we now use the name of the type, and report that
this type is unsupported.

gdb/ChangeLog:

* guile/scm-breakpoint.c (gdbscm_make_breakpoint): Split the error
for invalid breakpoint numbers, and unsupported breakpoint
numbers.

gdb/testsuite/ChangeLog:

* gdb.guile/scm-breakpoint.exp (test_watchpoints): Add new tests.

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

index 54f1b7bf539066dd4d23e656611908c4b00107ac..80ccc9f4c85c8f7da5726eff228119adb91a3830 100644 (file)
@@ -1,3 +1,9 @@
+2021-06-25  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * guile/scm-breakpoint.c (gdbscm_make_breakpoint): Split the error
+       for invalid breakpoint numbers, and unsupported breakpoint
+       numbers.
+
 2021-06-25  Tom Tromey  <tom@tromey.com>
 
        * dwarf2/index-write.c (struct addrmap_index_data): Add
index 4ff197e48a45374b0a070cb5e62689bf047e69b1..346b00629b0aedf290fcaab01f3584c7ff9d951a 100644 (file)
@@ -387,8 +387,19 @@ gdbscm_make_breakpoint (SCM location_scm, SCM rest)
                                     _("invalid watchpoint class"));
        }
       break;
+    case bp_none:
+    case bp_hardware_watchpoint:
+    case bp_read_watchpoint:
+    case bp_access_watchpoint:
+      {
+       const char *type_name = bpscm_type_to_string (type);
+       gdbscm_misc_error (FUNC_NAME, type_arg_pos,
+                          gdbscm_scm_from_c_string (type_name),
+                          _("unsupported breakpoint type"));
+      }
+      break;
     default:
-      gdbscm_out_of_range_error (FUNC_NAME, access_type_arg_pos,
+      gdbscm_out_of_range_error (FUNC_NAME, type_arg_pos,
                                 scm_from_int (type),
                                 _("invalid breakpoint type"));
     }
index 040a12fe879582253c1cfb9571c7b39135d8250c..330e7c84f1ad3d8eeb73e559ef7f6142b0137009 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-25  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.guile/scm-breakpoint.exp (test_watchpoints): Add new tests.
+
 gdb/testsuite/ChangeLog
 2021-06-25  Carl Love  <cel@us.ibm.com>
 
index 56058942e64637f1d2d3aa5690d13ba3a54be2f8..0e9e64ed4aed4ec0d00a6448db6b2d41a06e7cab 100644 (file)
@@ -258,6 +258,13 @@ proc_with_prefix test_watchpoints { } {
     gdb_test "continue" \
        ".*\[Ww\]atchpoint.*result.*Old value = 0.*New value = 25.*main.*" \
        "test watchpoint write"
+
+    gdb_test "guile (define wp2 (make-breakpoint \"result\" #:wp-class WP_WRITE #:type 999))" \
+       "ERROR: In procedure gdbscm_make_breakpoint: Out of range: invalid breakpoint type in position 5: 999\r\n.*" \
+       "create a breakpoint with an invalid type number"
+    gdb_test "guile (define wp2 (make-breakpoint \"result\" #:wp-class WP_WRITE #:type BP_NONE))" \
+       "ERROR: In procedure gdbscm_make_breakpoint: unsupported breakpoint type in position 5: \"BP_NONE\"\r\n.*" \
+       "create a breakpoint with an unsupported type"
 }
 
 proc_with_prefix test_bkpt_internal { } {