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

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