Blame SOURCES/gdb-enable-count-crash.patch

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