Add set/show debug dwarf-line.
[deliverable/binutils-gdb.git] / gdb / linespec.c
index 265742d9ac4b40d00cbf97d7cbeb74ebbd7e4b34..d2089b5dd9d1dae7324983e2d537110152b08083 100644 (file)
@@ -246,6 +246,7 @@ typedef enum ls_token_type linespec_token_type;
 /* List of keywords  */
 
 static const char * const linespec_keywords[] = { "if", "thread", "task" };
+#define IF_KEYWORD_INDEX 0
 
 /* A token of the linespec lexer  */
 
@@ -290,11 +291,6 @@ struct ls_parser
   /* Is the entire linespec quote-enclosed?  */
   int is_quote_enclosed;
 
-  /* Is a keyword syntactically valid at this point?
-     In, e.g., "break thread thread 1", the leading "keyword" must not
-     be interpreted as such.  */
-  int keyword_ok;
-
   /* The state of the parse.  */
   struct linespec_state state;
 #define PARSER_STATE(PPTR) (&(PPTR)->state)
@@ -418,10 +414,9 @@ linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp)
   return 1;
 }
 
-/* Does P represent one of the keywords?  If so, return
-   the keyword.  If not, return NULL.  */
+/* See linespec.h.  */
 
-static const char *
+const char *
 linespec_lexer_lex_keyword (const char *p)
 {
   int i;
@@ -433,11 +428,34 @@ 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 not a valid identifier character,
-            we have found a keyword.  */
+            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
-             && !(isalnum (p[len]) || p[len] == '_'))
-           return linespec_keywords[i];
+             && isspace (p[len]))
+           {
+             int 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 (i != IF_KEYWORD_INDEX)
+               {
+                 p += len;
+                 p = skip_spaces_const (p);
+                 for (j = 0; j < ARRAY_SIZE (linespec_keywords); ++j)
+                   {
+                     int nextlen = strlen (linespec_keywords[j]);
+
+                     if (strncmp (p, linespec_keywords[j], nextlen) == 0
+                         && isspace (p[nextlen]))
+                       return NULL;
+                   }
+               }
+
+             return linespec_keywords[i];
+           }
        }
     }
 
@@ -734,13 +752,16 @@ linespec_lexer_lex_one (linespec_parser *parser)
       PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
 
       /* Check for a keyword, they end the linespec.  */
-      keyword = NULL;
-      if (parser->keyword_ok)
-       keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
+      keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
       if (keyword != NULL)
        {
          parser->lexer.current.type = LSTOKEN_KEYWORD;
          LS_TOKEN_KEYWORD (parser->lexer.current) = keyword;
+         /* We do not advance the stream here intentionally:
+            we would like lexing to stop when a keyword is seen.
+
+            PARSER_STREAM (parser) +=  strlen (keyword);  */
+
          return parser->lexer.current;
        }
 
@@ -2175,10 +2196,6 @@ parse_linespec (linespec_parser *parser, const char **argptr)
        }
     }
 
-  /* A keyword at the start cannot be interpreted as such.
-     Consider "b thread thread 42".  */
-  parser->keyword_ok = 0;
-
   parser->lexer.saved_arg = *argptr;
   parser->lexer.stream = argptr;
 
@@ -2250,9 +2267,6 @@ parse_linespec (linespec_parser *parser, const char **argptr)
   else if (token.type != LSTOKEN_STRING && token.type != LSTOKEN_NUMBER)
     unexpected_linespec_error (parser);
 
-  /* Now we can recognize keywords.  */
-  parser->keyword_ok = 1;
-
   /* Shortcut: If the next token is not LSTOKEN_COLON, we know that
      this token cannot represent a filename.  */
   token = linespec_lexer_peek_token (parser);
@@ -2260,22 +2274,22 @@ parse_linespec (linespec_parser *parser, const char **argptr)
   if (token.type == LSTOKEN_COLON)
     {
       char *user_filename;
-      volatile struct gdb_exception ex;
 
       /* Get the current token again and extract the filename.  */
       token = linespec_lexer_lex_one (parser);
       user_filename = copy_token_string (token);
 
       /* Check if the input is a filename.  */
-      TRY_CATCH (ex, RETURN_MASK_ERROR)
+      TRY
        {
          PARSER_RESULT (parser)->file_symtabs
            = symtabs_from_filename (user_filename);
        }
-      if (ex.reason < 0)
+      CATCH (ex, RETURN_MASK_ERROR)
        {
          file_exception = ex;
        }
+      END_CATCH
 
       if (file_exception.reason >= 0)
        {
@@ -3106,7 +3120,6 @@ find_linespec_symbols (struct linespec_state *state,
   struct cleanup *cleanup;
   char *canon;
   const char *lookup_name;
-  volatile struct gdb_exception except;
 
   cleanup = demangle_for_lookup (name, state->language->la_language,
                                 &lookup_name);
@@ -3194,7 +3207,7 @@ find_linespec_symbols (struct linespec_state *state,
       if (!VEC_empty (symbolp, classes))
        {
          /* Now locate a list of suitable methods named METHOD.  */
-         TRY_CATCH (except, RETURN_MASK_ERROR)
+         TRY
            {
              find_method (state, file_symtabs, klass, method, classes,
                           symbols, minsyms);
@@ -3202,11 +3215,12 @@ find_linespec_symbols (struct linespec_state *state,
 
          /* If successful, we're done.  If NOT_FOUND_ERROR
             was not thrown, rethrow the exception that we did get.  */
-         if (except.reason < 0)
+         CATCH (except, RETURN_MASK_ERROR)
            {
              if (except.error != NOT_FOUND_ERROR)
                throw_exception (except);
            }
+         END_CATCH
        }
     }
 
This page took 0.02516 seconds and 4 git commands to generate.