From: Joel Brobecker Date: Fri, 7 Feb 2014 04:44:20 +0000 (-0500) Subject: Wrong type for 'Length result. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=aa4fb036e90f5c976f57cd08f2c024cb0fe24897;p=binutils-gdb.git 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7a516175317..84162d2af74 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2014-02-10 Joel Brobecker + + * ada-lang.c (ada_evaluate_subexp): Set the type of the value + returned by the 'Length attribute to integer. + 2014-02-10 Joel Brobecker * ada-lang.c (_initialize_ada_language): Initialize diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index a4accaca8a2..e69ed8165ff 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); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index da1348b3016..a9021cbbb1c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-02-10 Joel Brobecker + + * gdb.ada/tick_length_array_enum_idx: New testcase. + 2014-02-10 Doug Evans * configure.ac (AC_OUTPUT): Add gdb.guile. diff --git a/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp new file mode 100644 index 00000000000..86a9c207710 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp @@ -0,0 +1,41 @@ +# Copyright 2014 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "ada.exp" + +standard_ada_testfile foo_n207_004 + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/foo_n207_004.adb] +runto "foo_n207_004.adb:$bp_location" + +gdb_test "print full'length" "= 5" +gdb_test "print prim'length" "= 3" +gdb_test "print cold'length" "= 3" +gdb_test "print vars'length" "= 2" + +gdb_test "ptype full'length" "type = <$decimal-byte integer>" +gdb_test "ptype prim'length" "type = <$decimal-byte integer>" +gdb_test "ptype cold'length" "type = <$decimal-byte integer>" +gdb_test "ptype vars'length" "type = <$decimal-byte integer>" + +gdb_test "ptype full_table'length" "type = <$decimal-byte integer>" +gdb_test "ptype primary_table'length" "type = <$decimal-byte integer>" +gdb_test "ptype variable_table'length" "type = <$decimal-byte integer>" diff --git a/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb new file mode 100644 index 00000000000..51f3c55e990 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb @@ -0,0 +1,28 @@ +-- Copyright 2014 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with Pck; use Pck; + +procedure Foo_n207_004 is + Full : Full_Table := (False, True, False, True, False); + Prim : Primary_Table := (True, False, False); + Cold : Variable_Table := (Green => False, Blue => True, White => True); + Vars : Variable_Table := New_Variable_Table (Low => Red, High => Green); +begin + Do_Nothing (Full'Address); -- STOP + Do_Nothing (Prim'Address); + Do_Nothing (Cold'Address); + Do_Nothing (Vars'Address); +end Foo_n207_004; diff --git a/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.adb b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.adb new file mode 100644 index 00000000000..cf145fd2633 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.adb @@ -0,0 +1,34 @@ +-- Copyright 2014 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +package body Pck is + + function New_Variable_Table (Low: Color; High: Color) return Variable_Table + is + Result : Variable_Table (Low .. High); + begin + for J in Low .. High loop + Result (J) := (J = Black or J = Green or J = White); + end loop; + return Result; + end New_Variable_Table; + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; +end Pck; + + diff --git a/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.ads b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.ads new file mode 100644 index 00000000000..b9a42cabc92 --- /dev/null +++ b/gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.ads @@ -0,0 +1,28 @@ +-- Copyright 2014 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +with System; +package Pck is + type Color is (Black, Red, Green, Blue, White); + + type Full_Table is array (Color) of Boolean; + type Primary_Table is array (Color range Red .. Blue) of Boolean; + type Variable_Table is array (Color range <>) of Boolean; + + function New_Variable_Table (Low: Color; High: Color) return Variable_Table; + + procedure Do_Nothing (A : System.Address); +end Pck; +