aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2014-02-06 23:44:20 -0500
committerJoel Brobecker <brobecker@adacore.com>2014-02-10 13:15:43 +0400
commitaa4fb036e90f5c976f57cd08f2c024cb0fe24897 (patch)
tree60e0046ff631e59ebd0bef7cd86a68956fe4d617
parent9dee8cc6aa668228309de7d0e23e1775beb7d12f (diff)
downloadgdb-aa4fb036e90f5c976f57cd08f2c024cb0fe24897.zip
gdb-aa4fb036e90f5c976f57cd08f2c024cb0fe24897.tar.gz
gdb-aa4fb036e90f5c976f57cd08f2c024cb0fe24897.tar.bz2
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.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ada-lang.c20
-rw-r--r--gdb/testsuite/ChangeLog4
-rw-r--r--gdb/testsuite/gdb.ada/tick_length_array_enum_idx.exp41
-rw-r--r--gdb/testsuite/gdb.ada/tick_length_array_enum_idx/foo_n207_004.adb28
-rw-r--r--gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.adb34
-rw-r--r--gdb/testsuite/gdb.ada/tick_length_array_enum_idx/pck.ads28
7 files changed, 155 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7a51617..84162d2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2014-02-10 Joel Brobecker <brobecker@adacore.com>
+ * ada-lang.c (ada_evaluate_subexp): Set the type of the value
+ returned by the 'Length attribute to integer.
+
+2014-02-10 Joel Brobecker <brobecker@adacore.com>
+
* ada-lang.c (_initialize_ada_language): Initialize
cache_space obstack.
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);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index da1348b..a9021cb 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2014-02-10 Joel Brobecker <brobecker@adacore.com>
+
+ * gdb.ada/tick_length_array_enum_idx: New testcase.
+
2014-02-10 Doug Evans <xdje42@gmail.com>
* 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 0000000..86a9c20
--- /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 <http://www.gnu.org/licenses/>.
+
+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 0000000..51f3c55
--- /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 <http://www.gnu.org/licenses/>.
+
+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 0000000..cf145fd
--- /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 <http://www.gnu.org/licenses/>.
+
+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 0000000..b9a42ca
--- /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 <http://www.gnu.org/licenses/>.
+
+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;
+