gdb/mi: handle no condition argument case for -break-condition
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 26 Jul 2021 06:25:03 +0000 (08:25 +0200)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 26 Jul 2021 06:28:12 +0000 (08:28 +0200)
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 <number> and/or <expr> 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/ChangeLog:
2021-07-26  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

PR gdb/28076
* mi/mi-cmd-break.c (mi_cmd_break_condition): Handle the case
of having no condition argument.

gdb/doc/ChangeLog:
2021-07-26  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

PR gdb/28076
* gdb.texinfo (GDB/MI Breakpoint Commands): Mention clearing
the condition in the -break-condition command.

gdb/testsuite/ChangeLog:
2021-07-26  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

PR gdb/28076
* gdb.mi/mi-break.exp: Add more tests to check clearing the
breakpoint condition.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/mi/mi-cmd-break.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-break.exp

index 4300dc88492bb2bb7035c819c195d3d37ccd704a..2923c592a2f0a84e6ae668f40d7ffdaf6d8b6296 100644 (file)
@@ -1,3 +1,9 @@
+2021-07-26  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       PR gdb/28076
+       * mi/mi-cmd-break.c (mi_cmd_break_condition): Handle the case
+       of having no condition argument.
+
 2021-07-20  Luis Machado  <luis.machado@linaro.org>
            Pedro Alves  <pedro@palves.net>
 
index 0df8399caa30207ff13246f322b0818ef29059df..9adc42414a0c9c43e41fdc9d1de1741507273519 100644 (file)
@@ -1,3 +1,9 @@
+2021-07-26  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       PR gdb/28076
+       * gdb.texinfo (GDB/MI Breakpoint Commands): Mention clearing
+       the condition in the -break-condition command.
+
 2021-07-02  Pedro Alves  <pedro@palves.net>
 
        * gdb.texinfo (TUI): <TUI Mouse Support>: New node/section.
index a16a3825ebb82502f952c60fbb236b09b9b92388..a486bbe3607991174aac7ac9c5911967f3dd4871 100644 (file)
@@ -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
 
index 5439937f66bc8530f16b8b4160652a81339eda3c..c2d642d75b4059aa34821ceafb2fd95e22f68d1b 100644 (file)
@@ -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 <number> and/or <expr> "
-            "argument"));
+  /* There must be at least one more arg: a bpnum.  */
+  if (oind >= argc)
+    error (_("-break-condition: Missing the <number> 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 */,
index ac96462e7ce4a3b78177ea89614901204a7c5353..8be35e315a4178869e756eee45ff4ebe9e4894ce 100644 (file)
@@ -1,3 +1,9 @@
+2021-07-26  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       PR gdb/28076
+       * gdb.mi/mi-break.exp: Add more tests to check clearing the
+       breakpoint condition.
+
 2021-07-22  Tom de Vries  <tdevries@suse.de>
 
        * gdb.ada/formatted_ref.exp: Add xfail for PR gcc/101575.
index b6ef34830047b62f698cf21358e5358d4dbec078..f5e8ef7be47562c97a4db9bae1ac3cbe3bc49e69 100644 (file)
@@ -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 <number> 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 <number> argument\"" \
+       "no arguments with --force"
 }
 
 proc test_break {mi_mode} {
This page took 0.059068 seconds and 4 git commands to generate.