aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPierre-Marie de Rodat <derodat@adacore.com>2015-09-04 13:09:00 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2015-09-14 16:28:23 +0200
commit919e6dbe9b61a27e8f7f89121ba182907df461a3 (patch)
treed32eab262f69f68bcd264539830f600ed774b3df /gdb
parentb027a8fa7dc4854e72ddada0b495b52166be2974 (diff)
downloadgdb-919e6dbe9b61a27e8f7f89121ba182907df461a3.zip
gdb-919e6dbe9b61a27e8f7f89121ba182907df461a3.tar.gz
gdb-919e6dbe9b61a27e8f7f89121ba182907df461a3.tar.bz2
[Ada] Fix the evaluation of access to packed array subscript
This change is relevant only for standard DWARF (as opposed to the GNAT encodings extensions): at the time of writing it only makes a difference with GCC patches that are to be integrated: see in particular <https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01364.html>. Given the following Ada declarations: type Small is mod 2 ** 6; type Array_Type is array (0 .. 9) of Small with Pack; type Array_Access is access all Array_Type; A : aliased Array_Type := (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); AA : constant Array_Type := A'Access; Before this change, we would get the following GDB session: (gdb) print aa.all(2) $1 = 3 (gdb) print aa(2) $2 = 16 This is wrong: both expression should yield the same value: 3. The problem is simply that the routine which handles accesses to arrays lack general handling for packed arrays. After this patch, we have the expected output: (gdb) print aa.all(2) $1 = 3 (gdb) print aa(2) $2 = 3 gdb/ChangeLog: * ada-lang.c (ada_value_ptr_subscript): Update the heading comment. Handle packed arrays. gdb/testsuite/ChangeLog: * gdb.ada/access_to_packed_array.exp: New testcase. * gdb.ada/access_to_packed_array/foo.adb: New file. * gdb.ada/access_to_packed_array/pack.adb: New file. * gdb.ada/access_to_packed_array/pack.ads: New file. Tested on x86_64-linux, no regression.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ada-lang.c17
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.ada/access_to_packed_array.exp33
-rw-r--r--gdb/testsuite/gdb.ada/access_to_packed_array/foo.adb21
-rw-r--r--gdb/testsuite/gdb.ada/access_to_packed_array/pack.adb23
-rw-r--r--gdb/testsuite/gdb.ada/access_to_packed_array/pack.ads29
7 files changed, 133 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index dadb7a0..3ca1bf1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-14 Pierre-Marie de Rodat <derodat@adacore.com>
+
+ * ada-lang.c (ada_value_ptr_subscript): Update the heading
+ comment. Handle packed arrays.
+
2015-09-14 Pedro Alves <palves@redhat.com>
* NEWS (Changes in GDB 7.10, New commands>: Remove duplicate
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d166d1c..49f3d9a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2757,14 +2757,27 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind)
/* Assuming ARR is a pointer to a GDB array, the value of the element
of *ARR at the ARITY indices given in IND.
- Does not read the entire array into memory. */
+ Does not read the entire array into memory.
+
+ Note: Unlike what one would expect, this function is used instead of
+ ada_value_subscript for basically all non-packed array types. The reason
+ for this is that a side effect of doing our own pointer arithmetics instead
+ of relying on value_subscript is that there is no implicit typedef peeling.
+ This is important for arrays of array accesses, where it allows us to
+ preserve the fact that the array's element is an array access, where the
+ access part os encoded in a typedef layer. */
static struct value *
ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind)
{
int k;
+ struct value *array_ind = ada_value_ind (arr);
struct type *type
- = check_typedef (value_enclosing_type (ada_value_ind (arr)));
+ = check_typedef (value_enclosing_type (array_ind));
+
+ if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+ && TYPE_FIELD_BITSIZE (type, 0) > 0)
+ return value_subscript_packed (array_ind, arity, ind);
for (k = 0; k < arity; k += 1)
{
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e135b56..17b264d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2015-09-14 Pierre-Marie de Rodat <derodat@adacore.com>
+
+ * gdb.ada/access_to_packed_array.exp: New testcase.
+ * gdb.ada/access_to_packed_array/foo.adb: New file.
+ * gdb.ada/access_to_packed_array/pack.adb: New file.
+ * gdb.ada/access_to_packed_array/pack.ads: New file.
+
2015-09-14 Markus Metzger <markus.t.metzger@intel.com>
* gdb.btrace/buffer-size.exp: Remove recording with unlimited BTS
diff --git a/gdb/testsuite/gdb.ada/access_to_packed_array.exp b/gdb/testsuite/gdb.ada/access_to_packed_array.exp
new file mode 100644
index 0000000..0dca780
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/access_to_packed_array.exp
@@ -0,0 +1,33 @@
+# 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 pack.a" "\\(0 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\\)")
+gdb_test "pack.aa" "\\(access pack\\.array_type\\) 0x.* <pack\\.a>")
+
+gdb_test "pack.a(2)" "3"
+gdb_test "pack.aa(2)" "3"
diff --git a/gdb/testsuite/gdb.ada/access_to_packed_array/foo.adb b/gdb/testsuite/gdb.ada/access_to_packed_array/foo.adb
new file mode 100644
index 0000000..71ae5bf
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/access_to_packed_array/foo.adb
@@ -0,0 +1,21 @@
+-- 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 Pack;
+
+procedure Foo is
+begin
+ Pack.Do_Nothing (Pack.AA); -- BREAK
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/access_to_packed_array/pack.adb b/gdb/testsuite/gdb.ada/access_to_packed_array/pack.adb
new file mode 100644
index 0000000..60d752d
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/access_to_packed_array/pack.adb
@@ -0,0 +1,23 @@
+-- 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 body Pack is
+
+ procedure Do_Nothing (A : Array_Access) is
+ begin
+ null;
+ end Do_Nothing;
+
+end Pack;
diff --git a/gdb/testsuite/gdb.ada/access_to_packed_array/pack.ads b/gdb/testsuite/gdb.ada/access_to_packed_array/pack.ads
new file mode 100644
index 0000000..bb08742
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/access_to_packed_array/pack.ads
@@ -0,0 +1,29 @@
+-- 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 Small is mod 2 ** 6;
+ type Array_Type is array (0 .. 9) of Small
+ with Pack;
+ type Array_Access is access all Array_Type;
+
+ A : aliased Array_Type :=
+ (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ AA : constant Array_Access := A'Access;
+
+ procedure Do_Nothing (A : Array_Access);
+
+end Pack;