aboutsummaryrefslogtreecommitdiff
path: root/gdb/breakpoint.c
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2020-10-27 10:56:03 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2020-10-27 11:00:57 +0100
commit733d554a4625db4ffb89b7a20e1cf27ab071ef4d (patch)
treed80ff024b78e88d2eba1c53d91766761a0ee92e8 /gdb/breakpoint.c
parentb5fa468fef441528147c3a47b085612d5305f181 (diff)
downloadgdb-733d554a4625db4ffb89b7a20e1cf27ab071ef4d.zip
gdb-733d554a4625db4ffb89b7a20e1cf27ab071ef4d.tar.gz
gdb-733d554a4625db4ffb89b7a20e1cf27ab071ef4d.tar.bz2
gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition
The previous patch made it possible to define a condition if it's valid at some locations. If the condition is invalid at all of the locations, it's rejected. However, there may be cases where the user knows the condition *will* be valid at a location in the future, e.g. due to a shared library load. To make it possible that such condition can be defined, this patch adds an optional '-force' flag to the 'condition' command, and, respectively, a '-force-condition' flag to the 'break'command. When the force flag is passed, the condition is not rejected even when it is invalid for all the current locations (note that all the locations would be internally disabled in this case). For instance: (gdb) break test.c:5 Breakpoint 1 at 0x1155: file test.c, line 5. (gdb) cond 1 foo == 42 No symbol "foo" in current context. Defining the condition was not possible because 'foo' is not available. The user can override this behavior with the '-force' flag: (gdb) cond -force 1 foo == 42 warning: failed to validate condition at location 1.1, disabling: No symbol "foo" in current context. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y <MULTIPLE> stop only if foo == 42 1.1 N 0x0000000000001155 in main at test.c:5 Now the condition is accepted, but the location is automatically disabled. If a future location has a context in which 'foo' is available, that location would be enabled. For the 'break' command, -force-condition has the same result: (gdb) break test.c:5 -force-condition if foo == 42 warning: failed to validate condition at location 0x1169, disabling: No symbol "foo" in current context. Breakpoint 1 at 0x1169: file test.c, line 5. gdb/ChangeLog: 2020-10-27 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * breakpoint.h (set_breakpoint_condition): Add a new bool parameter. * breakpoint.c: Update the help text of the 'condition' and 'break' commands. (set_breakpoint_condition): Take a new bool parameter to control whether condition definition should be forced even when the condition expression is invalid in all of the current locations. (condition_command): Update the call to 'set_breakpoint_condition'. (find_condition_and_thread): Take the "-force-condition" flag into account. * linespec.c (linespec_keywords): Add "-force-condition" as an element. (FORCE_KEYWORD_INDEX): New #define. (linespec_lexer_lex_keyword): Update to consider "-force-condition" as a keyword. * ada-lang.c (create_ada_exception_catchpoint): Ditto. * guile/scm-breakpoint.c (gdbscm_set_breakpoint_condition_x): Ditto. * python/py-breakpoint.c (bppy_set_condition): Ditto. * NEWS: Mention the changes to the 'break' and 'condition' commands. gdb/testsuite/ChangeLog: 2020-10-27 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.base/condbreak-multi-context.exp: Expand to test forcing the condition. * gdb.linespec/cpcompletion.exp: Update to consider the '-force-condition' keyword. * gdb.linespec/explicit.exp: Ditto. * lib/completion-support.exp: Ditto. gdb/doc/ChangeLog: 2020-10-27 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> * gdb.texinfo (Set Breaks): Document the '-force-condition' flag of the 'break'command. * gdb.texinfo (Conditions): Document the '-force' flag of the 'condition' command.
Diffstat (limited to 'gdb/breakpoint.c')
-rw-r--r--gdb/breakpoint.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 0d3fd0c..152f406 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -882,7 +882,7 @@ set_breakpoint_location_condition (const char *cond_string, bp_location *loc,
void
set_breakpoint_condition (struct breakpoint *b, const char *exp,
- int from_tty)
+ int from_tty, bool force)
{
if (*exp == 0)
{
@@ -950,8 +950,9 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
catch (const gdb_exception_error &e)
{
/* Condition string is invalid. If this happens to
- be the last loc, abandon. */
- if (loc->next == nullptr)
+ be the last loc, abandon (if not forced) or continue
+ (if forced). */
+ if (loc->next == nullptr && !force)
throw;
}
}
@@ -1032,6 +1033,18 @@ condition_command (const char *arg, int from_tty)
error_no_arg (_("breakpoint number"));
p = arg;
+
+ /* Check if the "-force" flag was passed. */
+ bool force = false;
+ const char *tok = skip_spaces (p);
+ const char *end_tok = skip_to_space (tok);
+ int toklen = end_tok - tok;
+ if (toklen >= 1 && strncmp (tok, "-force", toklen) == 0)
+ {
+ force = true;
+ p = end_tok + 1;
+ }
+
bnum = get_number (&p);
if (bnum == 0)
error (_("Bad breakpoint argument: '%s'"), arg);
@@ -1051,7 +1064,7 @@ condition_command (const char *arg, int from_tty)
" a %s stop condition defined for this breakpoint."),
ext_lang_capitalized_name (extlang));
}
- set_breakpoint_condition (b, p, from_tty);
+ set_breakpoint_condition (b, p, from_tty, force);
if (is_breakpoint (b))
update_global_location_list (UGLL_MAY_INSERT);
@@ -9172,6 +9185,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
*thread = -1;
*task = 0;
*rest = NULL;
+ bool force = false;
while (tok && *tok)
{
@@ -9195,10 +9209,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;
@@ -15252,7 +15281,8 @@ specified name as a complete fully-qualified name instead."
command. */
#define BREAK_ARGS_HELP(command) \
-command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\
+command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\
+\t[-force-condition] [if CONDITION]\n\
PROBE_MODIFIER shall be present if the command is to be placed in a\n\
probe point. Accepted values are `-probe' (for a generic, automatically\n\
guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\
@@ -15265,6 +15295,9 @@ stack frame. This is useful for breaking on return to a stack frame.\n\
\n\
THREADNUM is the number from \"info threads\".\n\
CONDITION is a boolean expression.\n\
+\n\
+With the \"-force-condition\" flag, the condition is defined even when\n\
+it is invalid for all current locations.\n\
\n" LOCATION_HELP_STRING "\n\n\
Multiple breakpoints at one place are permitted, and useful if their\n\
conditions are different.\n\
@@ -15586,8 +15619,10 @@ then no output is printed when it is hit, except what the commands print."));
c = add_com ("condition", class_breakpoint, condition_command, _("\
Specify breakpoint number N to break only if COND is true.\n\
-Usage is `condition N COND', where N is an integer and COND is an\n\
-expression to be evaluated whenever breakpoint N is reached."));
+Usage is `condition [-force] N COND', where N is an integer and COND\n\
+is an expression to be evaluated whenever breakpoint N is reached.\n\
+With the \"-force\" flag, the condition is defined even when it is\n\
+invalid for all current locations."));
set_cmd_completer (c, condition_completer);
c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\