aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.ada
diff options
context:
space:
mode:
authorXavier Roirand <roirand@adacore.com>2018-01-07 23:56:36 -0500
committerJoel Brobecker <brobecker@adacore.com>2018-01-07 23:56:36 -0500
commit04bafb1ed002df1f25ca5a5773d87723a4baf46b (patch)
tree219c480a5fdbd864dbf046cdd8ad9a1963e3447b /gdb/testsuite/gdb.ada
parente09efd5931daf7eede1f4da46313a1aaadd4dbfa (diff)
downloadgdb-04bafb1ed002df1f25ca5a5773d87723a4baf46b.zip
gdb-04bafb1ed002df1f25ca5a5773d87723a4baf46b.tar.gz
gdb-04bafb1ed002df1f25ca5a5773d87723a4baf46b.tar.bz2
(Ada) Fix print of array using non-contiguous enumeration indexes
Consider the following code: type Index is (Index1, Index2); Size : constant Integer := 10; for Index use (Index1 => 1, Index2 => Size); type Array_Index_Enum is array (Index) of Integer; my_table : Array_Index_Enum :=(others => 42); When compiling the code above with a compiler where the GNAT encodings are turned off (which can be temporarily emulated by using the compiler switch -fgnat-encodings=minimal), printing this table in gdb leads to: (gdb) p my_table $1 = (42, 42, 4203344, 10, -8320, 32767, 4203465, 0, 0, 0) The displayed content is wrong since the handling part believes that the length of the array is max index value (10) minus the first index value (1) i+ 1 = 10 which is wrong since index are not contiguous in this case. The right behavior is to detect that the array is using enumeration index hence parse the enumeration values in order to get the number of indexes in this array (2 indexes here). This patch fixes this issue and changes the output as follow: (gdb) p my_table $1 = (42, 42) gdb/ChangeLog: * ada-valprint.c (val_print_packed_array_elements): Use proper number of elements when printing an array indexed by an enumeration type. gdb/testsuite/ChangeLog (Joel Brobecker <brobecker@adacore.com>): * gdb.ada/arr_enum_idx_w_gap.exp * gdb.ada/arr_enum_idx_w_gap/foo_q418_043.adb Tested on x86_64-linux.
Diffstat (limited to 'gdb/testsuite/gdb.ada')
-rw-r--r--gdb/testsuite/gdb.ada/arr_enum_idx_w_gap.exp33
-rw-r--r--gdb/testsuite/gdb.ada/arr_enum_idx_w_gap/foo_q418_043.adb24
2 files changed, 57 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.ada/arr_enum_idx_w_gap.exp b/gdb/testsuite/gdb.ada/arr_enum_idx_w_gap.exp
new file mode 100644
index 0000000..ad706d4
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/arr_enum_idx_w_gap.exp
@@ -0,0 +1,33 @@
+# Copyright 2018 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_q418_043
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/foo_q418_043.adb]
+if ![runto "foo_q418_043.adb:$bp_location" ] then {
+ perror "Couldn't run ${testfile}"
+ return
+}
+
+gdb_test "print A" \
+ " = \\(42, 42\\)"
diff --git a/gdb/testsuite/gdb.ada/arr_enum_idx_w_gap/foo_q418_043.adb b/gdb/testsuite/gdb.ada/arr_enum_idx_w_gap/foo_q418_043.adb
new file mode 100644
index 0000000..66ed5b4
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/arr_enum_idx_w_gap/foo_q418_043.adb
@@ -0,0 +1,24 @@
+-- Copyright 2018 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/>.
+
+procedure Foo_Q418_043 is
+ type Index is (Index1, Index2);
+ Size : constant Integer := 10;
+ for Index use (Index1 => 1, Index2 => Size);
+ type Array_Index_Enum is array (Index) of Integer;
+ A : Array_Index_Enum :=(others => 42);
+begin
+ A(Index2) := 4242; --BREAK
+end Foo_Q418_043;