diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 386cef7bd4e..f4ce3d34a0c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -30565,7 +30565,7 @@ times="0"@} @subsubheading Synopsis @smallexample - -break-condition [ --force ] @var{number} @var{expr} + -break-condition [ --force ] @var{number} [ @var{expr} ] @end smallexample Breakpoint @var{number} will stop the program only if the condition in @@ -30573,7 +30573,8 @@ Breakpoint @var{number} will stop the program only if the condition in @samp{-break-list} output (see the description of the @samp{-break-list} command below). If the @samp{--force} flag is passed, the condition is forcibly defined even when it is invalid for all locations of -breakpoint @var{number}. +breakpoint @var{number}. If the @var{expr} argument is omitted, +breakpoint @var{number} becomes unconditional. @subsubheading @value{GDBN} Command diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 5439937f66b..c2d642d75b4 100644 --- a/gdb/mi/mi-cmd-break.c +++ b/gdb/mi/mi-cmd-break.c @@ -423,20 +423,19 @@ mi_cmd_break_condition (const char *command, char **argv, int argc) } } - /* There must be at least two more args: a bpnum and a condition - expression. */ - if (oind + 1 >= argc) - error (_("-break-condition: Missing the and/or " - "argument")); + /* There must be at least one more arg: a bpnum. */ + if (oind >= argc) + error (_("-break-condition: Missing the argument")); int bpnum = atoi (argv[oind]); /* The rest form the condition expr. */ - std::string expr (argv[oind + 1]); - for (int i = oind + 2; i < argc; ++i) + std::string expr = ""; + for (int i = oind + 1; i < argc; ++i) { - expr += " "; expr += argv[i]; + if (i + 1 < argc) + expr += " "; } set_breakpoint_condition (bpnum, expr.c_str (), 0 /* from_tty */, diff --git a/gdb/testsuite/gdb.mi/mi-break.exp b/gdb/testsuite/gdb.mi/mi-break.exp index 430ce6f41c3..7d01a936947 100644 --- a/gdb/testsuite/gdb.mi/mi-break.exp +++ b/gdb/testsuite/gdb.mi/mi-break.exp @@ -435,6 +435,28 @@ proc_with_prefix test_forced_conditions {} { mi_gdb_test "-break-info 16" \ "\\^done,[mi_make_breakpoint_table [list $bp]]" \ "invalid condition is defined" + + # No cond argument should clear the condition. + mi_gdb_test "-break-condition 16" \ + "~\"Breakpoint 16's condition is now valid at location 1, enabling.*\\^done" \ + "clear the condition" + set bp [mi_make_breakpoint -number 16] + mi_gdb_test "-break-info 16" \ + "\\^done,[mi_make_breakpoint_table [list $bp]]" \ + "condition is cleared" + + # Zero-argument is an error. + mi_gdb_test "-break-condition" \ + "\\^error,msg=\"-break-condition: Missing the argument\"" \ + "no arguments to -break-condition" + + # Passing --force with no condition should not crash or raise an error. + mi_gdb_test "-break-condition --force 16" \ + "\\^done" \ + "clear the condition with --force" + mi_gdb_test "-break-condition --force" \ + "\\^error,msg=\"-break-condition: Missing the argument\"" \ + "no arguments with --force" } proc test_break {mi_mode} {