Fix crash when setting breakpoint condition

gdb could crash when setting a breakpoint condition on a breakpoint
when using the Ada language.  The problem occurred because the
ada_evaluate_subexp would try to evaluate the array to compute its
attributes, but evaluating can't really be done at this time.

This patch fixes the problem by arranging not to try to evaluate in
EVAL_AVOID_SIDE_EFFECTS mode when computing an attribute.

Tested on x86-64 Fedora 29.  Because this is Ada-specific, and because
Joel approved it internally, I am checking it in.

gdb/ChangeLog
2019-06-19  Tom Tromey  <tromey@adacore.com>

	* ada-lang.c (ada_evaluate_subexp) <case OP_ATR_FIRST>: Handle
	EVAL_AVOID_SIDE_EFFECTS specially.

gdb/testsuite/ChangeLog
2019-06-19  Tom Tromey  <tromey@adacore.com>

	* gdb.ada/length_cond.exp: New file.
	* gdb.ada/length_cond/length_cond.adb: New file.
	* gdb.ada/length_cond/pck.adb: New file.
	* gdb.ada/length_cond/pck.ads: New file.
This commit is contained in:
Tom Tromey
2019-05-30 14:13:10 -06:00
parent dcf3792354
commit 680e1beed3
7 changed files with 159 additions and 7 deletions

View File

@@ -11055,8 +11055,34 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
if (noside == EVAL_SKIP)
goto nosideret;
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
if (type_arg == NULL)
type_arg = value_type (arg1);
if (type_arg == NULL)
if (ada_is_constrained_packed_array_type (type_arg))
type_arg = decode_constrained_packed_array_type (type_arg);
if (!discrete_type_p (type_arg))
{
switch (op)
{
default: /* Should never happen. */
error (_("unexpected attribute encountered"));
case OP_ATR_FIRST:
case OP_ATR_LAST:
type_arg = ada_index_type (type_arg, tem,
ada_attribute_name (op));
break;
case OP_ATR_LENGTH:
type_arg = builtin_type (exp->gdbarch)->builtin_int;
break;
}
}
return value_zero (type_arg, not_lval);
}
else if (type_arg == NULL)
{
arg1 = ada_coerce_ref (arg1);
@@ -11073,9 +11099,6 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
type = builtin_type (exp->gdbarch)->builtin_int;
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return allocate_value (type);
switch (op)
{
default: /* Should never happen. */
@@ -11133,9 +11156,6 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
type = builtin_type (exp->gdbarch)->builtin_int;
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return allocate_value (type);
switch (op)
{
default: