From aa4fb036e90f5c976f57cd08f2c024cb0fe24897 Mon Sep 17 00:00:00 2001 From: Joel Brobecker Date: Thu, 6 Feb 2014 23:44:20 -0500 Subject: 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. --- gdb/ada-lang.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'gdb/ada-lang.c') diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index a4accac..e69ed81 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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); -- cgit v1.1