]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/breakpoint.c
gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition
[thirdparty/binutils-gdb.git] / gdb / breakpoint.c
index 0d3fd0c3d7e72e1e827ff3c64c5e114a7af3d1a0..152f4066b482537299b76d0efecbb59d2b181eac 100644 (file)
@@ -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, _("\