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