2c2fa1
http://sourceware.org/ml/gdb-patches/2013-06/msg00788.html
2c2fa1
Subject: [PATCH] "enable count" user input error handling (PR gdb/15678)
2c2fa1
2c2fa1
Typing "enable count" by itself crashes GDB. Also, if you omit the
2c2fa1
breakpoint number/range, the error message is not very clear:
2c2fa1
2c2fa1
(gdb) enable count 2
2c2fa1
warning: bad breakpoint number at or near ''
2c2fa1
(gdb) enable count
2c2fa1
Segmentation fault (core dumped)
2c2fa1
2c2fa1
With this patch, the error messages are slightly more helpful:
2c2fa1
2c2fa1
(gdb) enable count 2
2c2fa1
Argument required (one or more breakpoint numbers).
2c2fa1
(gdb) enable count
2c2fa1
Argument required (hit count).
2c2fa1
2c2fa1
They are not as helpful to the user as I would like, but it's better
2c2fa1
than crashing. Suggestions are welcome.
2c2fa1
2c2fa1
Simon
2c2fa1
2c2fa1
gdb/ChangeLog:
2c2fa1
2013-06-26  Simon Marchi  <simon.marchi@ericsson.com>
2c2fa1
2c2fa1
	* breakpoint.c (map_breakpoint_numbers): Check for empty args
2c2fa1
	string.
2c2fa1
	(enable_count_command): Check args for NULL value.
2c2fa1
2c2fa1
gdb/testsuite/ChangeLog:
2c2fa1
2013-06-26  Simon Marchi  <simon.marchi@ericsson.com>
2c2fa1
2c2fa1
	* gdb.base/ena-dis-br.exp: Test "enable count" for bad user input.
2c2fa1
---
2c2fa1
 gdb/breakpoint.c                      | 9 +++++++--
2c2fa1
 gdb/testsuite/gdb.base/ena-dis-br.exp | 8 ++++++++
2c2fa1
 2 files changed, 15 insertions(+), 2 deletions(-)
2c2fa1
2c2fa1
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
2c2fa1
index ccd05d9..5a0c5ab 100644
2c2fa1
--- a/gdb/breakpoint.c
2c2fa1
+++ b/gdb/breakpoint.c
2c2fa1
@@ -14389,7 +14389,7 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *,
2c2fa1
   int match;
2c2fa1
   struct get_number_or_range_state state;
2c2fa1
2c2fa1
-  if (args == 0)
2c2fa1
+  if (args == 0 || *args == '\0')
2c2fa1
     error_no_arg (_("one or more breakpoint numbers"));
2c2fa1
2c2fa1
   init_number_or_range (&state, args);
2c2fa1
@@ -14713,7 +14713,12 @@ do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr)
2c2fa1
 static void
2c2fa1
 enable_count_command (char *args, int from_tty)
2c2fa1
 {
2c2fa1
-  int count = get_number (&args);
2c2fa1
+  int count;
2c2fa1
+
2c2fa1
+  if (args == NULL)
2c2fa1
+    error_no_arg (_("hit count"));
2c2fa1
+
2c2fa1
+  count = get_number (&args);
2c2fa1
2c2fa1
   map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count);
2c2fa1
 }
2c2fa1
diff --git a/gdb/testsuite/gdb.base/ena-dis-br.exp b/gdb/testsuite/gdb.base/ena-dis-br.exp
2c2fa1
index b08b709..82aef64 100644
2c2fa1
--- a/gdb/testsuite/gdb.base/ena-dis-br.exp
2c2fa1
+++ b/gdb/testsuite/gdb.base/ena-dis-br.exp
2c2fa1
@@ -173,6 +173,14 @@ set bp [break_at $bp_location7 "line $bp_location7"]
2c2fa1
2c2fa1
 set bp2 [break_at marker1 " line ($bp_location15|$bp_location16)"]
2c2fa1
2c2fa1
+gdb_test "enable count" \
2c2fa1
+    "Argument required \\(hit count\\)\\." \
2c2fa1
+    "enable count missing arguments"
2c2fa1
+
2c2fa1
+gdb_test "enable count 2" \
2c2fa1
+    "Argument required \\(one or more breakpoint numbers\\)\\." \
2c2fa1
+    "enable count missing last argument"
2c2fa1
+
2c2fa1
 gdb_test_no_output "enable count 2 $bp" "disable break with count"
2c2fa1
2c2fa1
 gdb_test "continue" \
2c2fa1