diff options
author | Andrew Burgess <aburgess@redhat.com> | 2023-12-22 11:29:13 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-01-04 09:24:18 +0000 |
commit | b7a5722ebdd24a0d15d56e96d30a649ea1d7b0ee (patch) | |
tree | 17846ef2a41131008510993c370b92172320e768 /gdb/testsuite/gdb.base/exprs.exp | |
parent | e89496f42ac7b2d6fbba15f98f3caf496de050f4 (diff) | |
download | gdb-b7a5722ebdd24a0d15d56e96d30a649ea1d7b0ee.zip gdb-b7a5722ebdd24a0d15d56e96d30a649ea1d7b0ee.tar.gz gdb-b7a5722ebdd24a0d15d56e96d30a649ea1d7b0ee.tar.bz2 |
gdb: improve error reporting from expression parser
This commits changes how errors are reported from the expression
parser. Previously, parser errors were reported like this:
(gdb) p a1 +}= 432
A syntax error in expression, near `}= 432'.
(gdb) p a1 +
A syntax error in expression, near `'.
The first case is fine, a user can figure out what's going wrong, but
the second case is a little confusing; as the error occurred at the
end of the expression GDB just reports the empty string to the user.
After this commit the first case is unchanged, but the second case now
reports like this:
(gdb) p a1 +
A syntax error in expression, near the end of `a1 +'.
Which I think is clearer. There is a possible issue if the expression
being parsed is very long, GDB will repeat the whole expression. But
this issue already exists in the standard case; if the error occurs
early in a long expression GDB will repeat everything after the syntax
error. So I've not worried about this case in my new code either,
which keeps things simpler.
I did consider trying to have multi-line errors here, in the style
that gcc produces, with some kind of '~~~~~^' marker on the second
line to indicate where the error occurred; but I rejected this due to
the places in GDB where we catch an error and repackage the message
within some longer string, I don't think multi-line error messages
would work well in that case. At a minimum it would require some
significant work in order to make all our error handling multi-line
aware.
I've added a couple of extra tests in gdb.base/exprs.exp.
Approved-By: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'gdb/testsuite/gdb.base/exprs.exp')
-rw-r--r-- | gdb/testsuite/gdb.base/exprs.exp | 8 |
1 files changed, 8 insertions, 0 deletions
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'\\." |