Wrong type for 'Length result.

Consider the following code:

   type Color is (Black, Red, Green, Blue, White);
   type Primary_Table is array (Color range Red .. Blue) of Boolean;
   Prim : Primary_Table := (True, False, False);

GDB prints the length of arrays in a fairly odd way:

   (gdb) p prim'length
   $2 = blue

The length returned should be an integer, not the array index type,
and this patch fixes this.

gdb/ChangeLog:

	* ada-lang.c (ada_evaluate_subexp): Set the type of the value
	returned by the 'Length attribute to integer.

testsuite/ChangeLog:

	* gdb.ada/tick_length_array_enum_idx: New testcase.
This commit is contained in:
Joel Brobecker 2014-02-06 23:44:20 -05:00
parent 9dee8cc6aa
commit aa4fb036e9
7 changed files with 155 additions and 5 deletions

View file

@ -10410,10 +10410,15 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
if (ada_is_constrained_packed_array_type (value_type (arg1)))
arg1 = ada_coerce_to_simple_array (arg1);
type = ada_index_type (value_type (arg1), tem,
ada_attribute_name (op));
if (type == NULL)
if (op == OP_ATR_LENGTH)
type = builtin_type (exp->gdbarch)->builtin_int;
else
{
type = ada_index_type (value_type (arg1), tem,
ada_attribute_name (op));
if (type == NULL)
type = builtin_type (exp->gdbarch)->builtin_int;
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return allocate_value (type);
@ -10466,9 +10471,14 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
if (ada_is_constrained_packed_array_type (type_arg))
type_arg = decode_constrained_packed_array_type (type_arg);
type = ada_index_type (type_arg, tem, ada_attribute_name (op));
if (type == NULL)
if (op == OP_ATR_LENGTH)
type = builtin_type (exp->gdbarch)->builtin_int;
else
{
type = ada_index_type (type_arg, tem, ada_attribute_name (op));
if (type == NULL)
type = builtin_type (exp->gdbarch)->builtin_int;
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return allocate_value (type);