]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/linespec: relax the position of the '-force-condition' flag
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 7 Dec 2020 08:20:31 +0000 (09:20 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Mon, 7 Dec 2020 08:22:06 +0000 (09:22 +0100)
The break command's "-force-condition" flag is currently required to
be followed by the "if" keyword.  This prevents flexibility when using
other keywords, e.g. "thread":

  (gdb) break main -force-condition thread 1 if foo
  Function "main -force-condition" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) n

Remove the requirement that "-force-condition" is always followed by
an "if", so that more flexibility is obtained when positioning
keywords.

gdb/ChangeLog:
2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* linespec.c (linespec_lexer_lex_keyword): The "-force-condition"
keyword may be followed by any keyword.
* breakpoint.c (find_condition_and_thread): Advance 'tok' by
'toklen' in the case for "-force-condition".

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

* gdb.linespec/keywords.exp: Add tests to check positional
flexibility of "-force-condition".

gdb/ChangeLog
gdb/breakpoint.c
gdb/linespec.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.linespec/keywords.exp

index 64e38aebd91dcbfba3a37e77adab942741a76d30..60b3ce44af295644bddc5542cab214a5384d2fc2 100644 (file)
@@ -1,3 +1,10 @@
+2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * linespec.c (linespec_lexer_lex_keyword): The "-force-condition"
+       keyword may be followed by any keyword.
+       * breakpoint.c (find_condition_and_thread): Advance 'tok' by
+       'toklen' in the case for "-force-condition".
+
 2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        * main.c (catch_command_errors): Add a flag parameter; invoke
index 61fbc3b92b111963320fbb80f10f2d183a4dadf6..881686ff7a0409bce17add20abe2b1a88ba4b5ef 100644 (file)
@@ -9263,7 +9263,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
        }
       else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
        {
-         tok = cond_start = end_tok + 1;
+         tok = tok + toklen;
          force = true;
        }
       else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
index 3bf16c504a267fb0135f6f9e13caca3a91c54a01..9af8e52f53fdbd5db0fc7b32c86c576b68503493 100644 (file)
@@ -477,32 +477,45 @@ linespec_lexer_lex_keyword (const char *p)
        {
          int len = strlen (linespec_keywords[i]);
 
-         /* If P begins with one of the keywords and the next
-            character is whitespace, we may have found a keyword.
-            It is only a keyword if it is not followed by another
-            keyword.  */
-         if (strncmp (p, linespec_keywords[i], len) == 0
-             && isspace (p[len]))
+         /* If P begins with
+
+            - "thread" or "task" and the next character is
+            whitespace, we may have found a keyword.  It is only a
+            keyword if it is not followed by another keyword.
+
+            - "-force-condition", the next character may be EOF
+            since this keyword does not take any arguments.  Otherwise,
+            it should be followed by a keyword.
+
+            - "if", ALWAYS stop the lexer, since it is not possible to
+            predict what is going to appear in the condition, which can
+            only be parsed after SaLs have been found.  */
+         if (strncmp (p, linespec_keywords[i], len) == 0)
            {
              int j;
 
-             /* Special case: "-force" is always followed by an "if".  */
+             if (i == FORCE_KEYWORD_INDEX && p[len] == '\0')
+               return linespec_keywords[i];
+
+             if (!isspace (p[len]))
+               continue;
+
              if (i == FORCE_KEYWORD_INDEX)
                {
                  p += len;
                  p = skip_spaces (p);
-                 int nextlen = strlen (linespec_keywords[IF_KEYWORD_INDEX]);
-                 if (!(strncmp (p, linespec_keywords[IF_KEYWORD_INDEX], nextlen) == 0
-                       && isspace (p[nextlen])))
-                   return NULL;
-               }
+                 for (j = 0; linespec_keywords[j] != NULL; ++j)
+                   {
+                     int nextlen = strlen (linespec_keywords[j]);
 
-             /* Special case: "if" ALWAYS stops the lexer, since it
-                is not possible to predict what is going to appear in
-                the condition, which can only be parsed after SaLs have
-                been found.  */
+                     if (strncmp (p, linespec_keywords[j], nextlen) == 0
+                         && isspace (p[nextlen]))
+                       return linespec_keywords[i];
+                   }
+               }
              else if (i != IF_KEYWORD_INDEX)
                {
+                 /* We matched a "thread" or "task".  */
                  p += len;
                  p = skip_spaces (p);
                  for (j = 0; linespec_keywords[j] != NULL; ++j)
index 62228d44293764d49dca9bea7a1b7da336d779a5..3c28bc75a663f82f619a8017bdf3a28c1b129b66 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * gdb.linespec/keywords.exp: Add tests to check positional
+       flexibility of "-force-condition".
+
 2020-12-07  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        * gdb.base/bp-cmds-run-with-ex.c: New file.
index 93bdcc9fc64d5312286462e8a0c922b46658ed70..645f44fbb83ae58ea1541599040472702a135c47 100644 (file)
@@ -75,3 +75,15 @@ gdb_test "break task task 123" "Unknown task 123\\."
 # Test NULL location with valid conditional containing a keyword.
 gdb_breakpoint "thread if thread == 0"
 gdb_breakpoint "task if task == 0"
+
+# Test the positional flexibility of the "-force-condition" flag.
+foreach prefix {"" "thread 1 "} {
+    foreach suffix {"" " " " thread 1"} {
+       foreach cond {"" " if 1"} {
+           with_test_prefix "prefix: '$prefix', suffix: '$suffix', cond: '$cond'" {
+               gdb_breakpoint "main ${prefix}-force-condition${suffix}${cond}"\
+                   "message"
+           }
+       }
+    }
+}