From b6c4205149824bfc3e5ab9e12819dcc0fc2af29d Mon Sep 17 00:00:00 2001 From: Tankut Baris Aktemur Date: Mon, 26 Jul 2021 08:25:03 +0200 Subject: gdb/mi: handle no condition argument case for -break-condition As reported in PR gdb/28076 [1], passing no condition argument to the -break-condition command (e.g.: "-break-condition 2") should clear the condition for breakpoint 2, just like CLI's "condition 2", but instead an error message is returned: ^error,msg="-break-condition: Missing the and/or argument" The current implementation of the -break-condition command's argument handling (79aabb7308c "gdb/mi: add a '--force' flag to the '-break-condition' command") was done according to the documentation, where the condition argument seemed mandatory. However, the -break-condition command originally (i.e. before the 79aabb7308c patch) used the CLI's "cond" command, and back then not passing a condition argument was clearing out the condition. So, this is a regression in terms of the behavior. Fix the argument handling of the -break-condition command to allow not having a condition argument, and also update the document to make the behavior clear. Also add test cases to test the scenarios which were previously not covered. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=28076 --- gdb/mi/mi-cmd-break.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'gdb/mi') diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c index 5439937..c2d642d 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 */, -- cgit v1.1