aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorPierre-Marie de Rodat <derodat@adacore.com>2015-09-01 16:18:40 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2015-09-23 22:14:18 +0200
commite6c2c623f7736175e52fce2b61aab60c60eccdf5 (patch)
tree96702023fcb262163ec07db66506e92c3a8030a3 /gdb/testsuite
parentb6518b3871859f9eeb7653bf2f3baaa43fa0a5d0 (diff)
downloadgdb-e6c2c623f7736175e52fce2b61aab60c60eccdf5.zip
gdb-e6c2c623f7736175e52fce2b61aab60c60eccdf5.tar.gz
gdb-e6c2c623f7736175e52fce2b61aab60c60eccdf5.tar.bz2
[Ada] Fix handling of array renamings
Compilers can materialize renamings of arrays (or of accesses to arrays) in Ada into variables whose types are references to the actual array types. Before this change, trying to use such an array renaming yielded an error in GDB: (gdb) print my_array(1) cannot subscript or call a record (gdb) print my_array_ptr(1) cannot subscript or call something of type `(null)' This behavior comes from bad handling for array renamings, in particular the OP_FUNCALL expression operator handling from ada-lang.c (ada_evaluate_subexp): in one place we turn the reference into a pointer, but the code that follows expect the value to be an array. This patch fixes how we handle references in call/subscript evaluation so that we turn these references into the actual array values instead of pointers to them. gdb/ChangeLog: * ada-lang.c (ada_evaluate_subexp) <OP_FUNCALL>: When the input value is a reference, actually dereference it in order to get the underlying value. gdb/testsuite/ChangeLog: * gdb.ada/array_ptr_renaming.exp: New testcase. * gdb.ada/array_ptr_renaming/foo.adb: New file. * gdb.ada/array_ptr_renaming/pack.ads: New file. Tested on x86_64-linux, no regression.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.ada/array_ptr_renaming.exp39
-rw-r--r--gdb/testsuite/gdb.ada/array_ptr_renaming/foo.adb25
-rw-r--r--gdb/testsuite/gdb.ada/array_ptr_renaming/pack.ads25
4 files changed, 95 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8cb1b7f..efabcdf 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2015-09-23 Pierre-Marie de Rodat <derodat@adacore.com>
+
+ * gdb.ada/array_ptr_renaming.exp: New testcase.
+ * gdb.ada/array_ptr_renaming/foo.adb: New file.
+ * gdb.ada/array_ptr_renaming/pack.ads: New file.
+
2015-09-21 Pierre Langlois <pierre.langlois@arm.com>
* gdb.trace/ftrace-lock.c: New file.
diff --git a/gdb/testsuite/gdb.ada/array_ptr_renaming.exp b/gdb/testsuite/gdb.ada/array_ptr_renaming.exp
new file mode 100644
index 0000000..eece4a4
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/array_ptr_renaming.exp
@@ -0,0 +1,39 @@
+# Copyright 2015 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
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "BREAK" ${testdir}/foo.adb]
+runto "foo.adb:$bp_location"
+
+gdb_test "print nt" " = \\(10, 20\\)"
+gdb_test "print nt(1)" " = 10"
+
+# Accesses to arrays and unconstrained arrays have the same runtime
+# representation with GNAT (fat pointers). In this case, GDB "forgets" that
+# it's dealing with an access and prints directly the array contents. This
+# should be fixed some day.
+setup_kfail "gdb/NNNN" *-*-*
+gdb_test "print ntp" " = \\(access pack\\.table_type\\) $hex.*"
+gdb_test "print ntp.all" " = \\(3 => 30, 40\\)"
+gdb_test "print ntp(3)" " = 30"
diff --git a/gdb/testsuite/gdb.ada/array_ptr_renaming/foo.adb b/gdb/testsuite/gdb.ada/array_ptr_renaming/foo.adb
new file mode 100644
index 0000000..ead98bc
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/array_ptr_renaming/foo.adb
@@ -0,0 +1,25 @@
+-- Copyright 2015 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;
+with Pack;
+
+procedure Foo is
+ NT : Pack.Table_Type renames Pack.Table;
+ NTP : Pack.Table_Ptr_Type renames Pack.Table_Ptr;
+begin
+ NT := NT; -- BREAK
+ NTP := NTP;
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/array_ptr_renaming/pack.ads b/gdb/testsuite/gdb.ada/array_ptr_renaming/pack.ads
new file mode 100644
index 0000000..d88d046
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/array_ptr_renaming/pack.ads
@@ -0,0 +1,25 @@
+-- Copyright 2015 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 Pack is
+
+ type Table_Type is
+ array (Natural range <>) of Integer;
+ type Table_Ptr_Type is access all Table_Type;
+
+ Table : Table_Type := (1 => 10, 2 => 20);
+ Table_Ptr : aliased Table_Ptr_Type := new Table_Type'(3 => 30, 4 => 40);
+
+end Pack;