diff options
-rw-r--r-- | gdb/parse.c | 6 | ||||
-rw-r--r-- | gdb/parser-defs.h | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/exprs.exp | 8 |
3 files changed, 17 insertions, 1 deletions
diff --git a/gdb/parse.c b/gdb/parse.c index efac0de..e8bb112 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -252,7 +252,11 @@ parser_state::parse_error (const char *msg) if (this->prev_lexptr) this->lexptr = this->prev_lexptr; - error (_("A %s in expression, near `%s'."), msg, this->lexptr); + if (*this->lexptr == '\0') + error (_("A %s in expression, near the end of `%s'."), + msg, this->start_of_input); + else + error (_("A %s in expression, near `%s'."), msg, this->lexptr); } diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 24522bb..4472898 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -152,6 +152,7 @@ struct parser_state : public expr_builder expression_context_block (context_block), expression_context_pc (context_pc), lexptr (input), + start_of_input (input), block_tracker (tracker), comma_terminates ((flags & PARSER_COMMA_TERMINATES) != 0), parse_completion (completion), @@ -288,6 +289,9 @@ struct parser_state : public expr_builder Currently used only for error reporting. */ const char *prev_lexptr = nullptr; + /* A pointer to the start of the full input, used for error reporting. */ + const char *start_of_input = nullptr; + /* Number of arguments seen so far in innermost function call. */ int arglist_len = 0; diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index 79ae905..8c85b57 100644 --- a/gdb/testsuite/gdb.base/exprs.exp +++ b/gdb/testsuite/gdb.base/exprs.exp @@ -275,3 +275,11 @@ gdb_test "print null_t_struct && null_t_struct->v_int_member == 0" \ # Regression test for unusual function-call parse that caused a crash. gdb_test "print v_short++(97)" \ "cast the call to its declared return type" + +# Test for a syntax error at the end of an expression. +gdb_test "print v_short + " \ + "A syntax error in expression, near the end of `v_short \\+'\\." + +# Test for a syntax error in the middle of an expression. +gdb_test "print v_short =}{= 3" \ + "A syntax error in expression, near `\\}\\{= 3'\\." |