Re: [PATCH v4 2/2] gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition

Pedro Alves
2020-10-29T17:30:31Z

On 10/13/20 1:25 PM, Tankut Baris Aktemur via Gdb-patches wrote:
> @@ -9192,10 +9207,25 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
> if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
> {
> tok = cond_start = end_tok + 1;
> - parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
> + try
> + {
> + parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
> + }
> + catch (const gdb_exception_error &)
> + {
> + if (!force)
> + throw;
> + else
> + tok = tok + strlen (tok);
> + }
> cond_end = tok;
> *cond_string = savestring (cond_start, cond_end - cond_start);
> }
> + else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
> + {
> + tok = cond_start = end_tok + 1;
> + force = true;
> + }
> else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
> {
> const char *tmptok;

Is it important to handle "-force-condition" in this position, as opposed
to making it another option handled by string_to_explicit_location ?

As is, this doesn't work, for example:

(gdb) b -function main -force<TAB>

nor does:

(gdb) b -force-condition main if 0
invalid explicit location argument, "-force-condition"

IMO, ideally all '-' options would be handled in the same place.

At some point, I think it would be nice to convert the
"break" command to use gdb::option, but it isn't trivial.