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