[Ada] 'first/'last/'length of array whose bound is a discriminant
Consider the following code: type Table is array (Positive range <>) of Integer; type Object (N : Integer) is record Data : Table (1 .. N); end record; My_Object : Object := (N => 3, Data => (3, 5, 8)); Trying to print the range and length of the My_Object.Data array yields: (gdb) print my_object.data'first $1 = 1 (gdb) print my_object.data'last $2 = 0 (gdb) print my_object.data'length $3 = 0 The first one is correct, and that is thanks to the fact that the lower bound is statically known. However, for the upper bound, and consequently the array's length, the values are incorrect. It should be: (gdb) print my_object.data'last $2 = 3 (gdb) print my_object.data'length $3 = 3 What happens here is that ada_array_bound_from_type sees that our array has a parallel "___XA" type, and therefore tries to use it. In particular, it described our array's index type as: [...]___XDLU_1__n, which means lower bound = 1, and upper bound is value of "n". Unfortunately, ada_array_bound_from_type does not have access to the discriminant, and is therefore unable to compute the bound correctly. Fortunately, at this stage, the bound has already been computed a while ago, and therefore doesn't need to be re-computed here. This patch fixes the issue by ignoring that ___XA type if the array is marked as already fixed. This also fixes the same issue with packed arrays. gdb/ChangeLog: * ada-lang.c (ada_array_bound_from_type): Ignore array's parallel ___XA type if the array has already been fixed. gdb/testsuite/ChangeLog: * gdb.ada/var_arr_attrs: New testcase.
This commit is contained in:
parent
a300380e12
commit
bafffb51c4
7 changed files with 143 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
2015-01-15 Joel Brobecker <brobecker@adacore.com>
|
||||
|
||||
* ada-lang.c (ada_array_bound_from_type): Ignore array's parallel
|
||||
___XA type if the array has already been fixed.
|
||||
|
||||
2015-01-14 Yao Qi <yao@codesourcery.com>
|
||||
|
||||
* Makefile.in (ppc-linux.o): New rule.
|
||||
|
|
|
@ -2928,8 +2928,19 @@ ada_array_bound_from_type (struct type *arr_type, int n, int which)
|
|||
else
|
||||
type = arr_type;
|
||||
|
||||
index_type_desc = ada_find_parallel_type (type, "___XA");
|
||||
ada_fixup_array_indexes_type (index_type_desc);
|
||||
if (TYPE_FIXED_INSTANCE (type))
|
||||
{
|
||||
/* The array has already been fixed, so we do not need to
|
||||
check the parallel ___XA type again. That encoding has
|
||||
already been applied, so ignore it now. */
|
||||
index_type_desc = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
index_type_desc = ada_find_parallel_type (type, "___XA");
|
||||
ada_fixup_array_indexes_type (index_type_desc);
|
||||
}
|
||||
|
||||
if (index_type_desc != NULL)
|
||||
index_type = to_fixed_range_type (TYPE_FIELD_TYPE (index_type_desc, n - 1),
|
||||
NULL);
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2015-01-15 Joel Brobecker <brobecker@adacore.com>
|
||||
|
||||
* gdb.ada/var_arr_attrs: New testcase.
|
||||
|
||||
2015-01-14 Pedro Alves <palves@redhat.com>
|
||||
Joel Brobecker <brobecker@adacore.com>
|
||||
|
||||
|
|
39
gdb/testsuite/gdb.ada/var_arr_attrs.exp
Normal file
39
gdb/testsuite/gdb.ada/var_arr_attrs.exp
Normal file
|
@ -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_o115_002
|
||||
|
||||
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } {
|
||||
return -1
|
||||
}
|
||||
|
||||
clean_restart ${testfile}
|
||||
|
||||
set bp_location [gdb_get_line_number "STOP" ${testdir}/foo_o115_002.adb]
|
||||
runto "foo_o115_002.adb:$bp_location"
|
||||
|
||||
gdb_test "print my_object.data'first" " = 1"
|
||||
|
||||
gdb_test "print my_object.data'last" " = 3"
|
||||
|
||||
gdb_test "print my_object.data'length" " = 3"
|
||||
|
||||
gdb_test "print my_small_object.data'first" " = 1"
|
||||
|
||||
gdb_test "print my_small_object.data'last" " = 3"
|
||||
|
||||
gdb_test "print my_small_object.data'length" " = 3"
|
25
gdb/testsuite/gdb.ada/var_arr_attrs/foo_o115_002.adb
Normal file
25
gdb/testsuite/gdb.ada/var_arr_attrs/foo_o115_002.adb
Normal file
|
@ -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 Pck; use Pck;
|
||||
|
||||
procedure Foo_O115_002 is
|
||||
My_Object : Object := (N => 3, Data => (3, 5, 8));
|
||||
My_Small_Object : Small_Object := (N => 3, Data => (3, 5, 8));
|
||||
begin
|
||||
Do_Nothing (My_Object'Address); -- STOP
|
||||
Do_Nothing (My_Small_Object'Address);
|
||||
end Foo_O115_002;
|
||||
|
21
gdb/testsuite/gdb.ada/var_arr_attrs/pck.adb
Normal file
21
gdb/testsuite/gdb.ada/var_arr_attrs/pck.adb
Normal file
|
@ -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/>.
|
||||
|
||||
package body Pck is
|
||||
procedure Do_Nothing (A : System.Address) is
|
||||
begin
|
||||
null;
|
||||
end Do_Nothing;
|
||||
end Pck;
|
36
gdb/testsuite/gdb.ada/var_arr_attrs/pck.ads
Normal file
36
gdb/testsuite/gdb.ada/var_arr_attrs/pck.ads
Normal file
|
@ -0,0 +1,36 @@
|
|||
-- 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;
|
||||
package Pck is
|
||||
|
||||
type Table is array (Positive range <>) of Integer;
|
||||
|
||||
type Object (N : Integer) is record
|
||||
Data : Table (1 .. N);
|
||||
end record;
|
||||
|
||||
type Small is new Integer range 0 .. 255;
|
||||
for Small'Size use 8;
|
||||
|
||||
type Small_Table is array (Positive range <>) of Small;
|
||||
pragma Pack (Small_Table);
|
||||
|
||||
type Small_Object (N : Integer) is record
|
||||
Data : Table (1 .. N);
|
||||
end record;
|
||||
|
||||
procedure Do_Nothing (A : System.Address);
|
||||
end Pck;
|
Loading…
Reference in a new issue