-fsanitize=undefined pointed out this error:
runtime error: load of value
2887952, which is not a valid value for type 'exp_opcode'
This happens in gdb.ada/complete.exp when processing "complete p
my_glob". This does not parse, so the Ada parser throws an exception;
but then the code in parse_exp_in_context_1 accepts the expression
anyway. However, as no elements have been written to the expression,
undefined behavior results.
The fix is to notice this case in parse_exp_in_context_1. This patch
also adds an assertion to prefixify_expression to enforce this
pre-existing constraint.
gdb/ChangeLog
2018-10-03 Tom Tromey <tom@tromey.com>
* parse.c (prefixify_expression): Add assert.
(parse_exp_in_context_1): Throw exception if the expression is
empty.
+2018-10-03 Tom Tromey <tom@tromey.com>
+
+ * parse.c (prefixify_expression): Add assert.
+ (parse_exp_in_context_1): Throw exception if the expression is
+ empty.
+
2018-10-03 Tom Tromey <tom@tromey.com>
* dwarf2read.c (read_signed_leb128): Work in ULONGEST.
Update copyright year range in all GDB files.
-2018-01-01 Joel Brobecker <brobecker@adacore.com>
+2018-01-01, 18 Joel Brobecker <brobecker@adacore.com>
* copyright.py (BY_HAND): Remove gdb/testsuite/gdb.base/step-line.inp
and gdb/testsuite/gdb.base/step-line.c.
int
prefixify_expression (struct expression *expr)
{
+ gdb_assert (expr->nelts > 0);
int len = sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts);
struct expression *temp;
int inpos = expr->nelts, outpos = 0;
}
CATCH (except, RETURN_MASK_ALL)
{
- if (! parse_completion)
+ /* If parsing for completion, allow this to succeed; but if no
+ expression elements have been written, then there's nothing
+ to do, so fail. */
+ if (! parse_completion || ps.expout_ptr == 0)
throw_exception (except);
}
END_CATCH