Fix Ada "ptype" bug with array types
Using ptype on an array type in Ada can sometimes show an incorrect high bound. This happens because ada_evaluate_subexp will create an array with an incorrect upper bound in the EVAL_AVOID_SIDE_EFFECTS case. This patch fixes the problem by arranging to always create such an array with valid bounds. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-03-18 Tom Tromey <tromey@adacore.com> * ada-lang.c (empty_array): Add "high" parameter. (ada_evaluate_subexp): Update. gdb/testsuite/ChangeLog 2019-03-18 Joel Brobecker <brobecker@adacore.com> Tom Tromey <tromey@adacore.com> * gdb.ada/ptype_array/pck.adb: New file. * gdb.ada/ptype_array/pck.ads: New file. * gdb.ada/ptype_array/foo.adb: New file. * gdb.ada/ptype_array.exp: New file.
This commit is contained in:
parent
af60449c26
commit
bff8c71fd8
7 changed files with 131 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2019-03-18 Tom Tromey <tromey@adacore.com>
|
||||||
|
|
||||||
|
* ada-lang.c (empty_array): Add "high" parameter.
|
||||||
|
(ada_evaluate_subexp): Update.
|
||||||
|
|
||||||
2019-03-17 Sergei Trofimovich <siarheit@google.com>
|
2019-03-17 Sergei Trofimovich <siarheit@google.com>
|
||||||
|
|
||||||
* unittests/string_view-selftests.c: Define
|
* unittests/string_view-selftests.c: Define
|
||||||
|
|
|
@ -3173,16 +3173,18 @@ ada_array_length (struct value *arr, int n)
|
||||||
return high - low + 1;
|
return high - low + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An empty array whose type is that of ARR_TYPE (an array type),
|
/* An array whose type is that of ARR_TYPE (an array type), with
|
||||||
with bounds LOW to LOW-1. */
|
bounds LOW to HIGH, but whose contents are unimportant. If HIGH is
|
||||||
|
less than LOW, then LOW-1 is used. */
|
||||||
|
|
||||||
static struct value *
|
static struct value *
|
||||||
empty_array (struct type *arr_type, int low)
|
empty_array (struct type *arr_type, int low, int high)
|
||||||
{
|
{
|
||||||
struct type *arr_type0 = ada_check_typedef (arr_type);
|
struct type *arr_type0 = ada_check_typedef (arr_type);
|
||||||
struct type *index_type
|
struct type *index_type
|
||||||
= create_static_range_type
|
= create_static_range_type
|
||||||
(NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type0)), low, low - 1);
|
(NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type0)), low,
|
||||||
|
high < low ? low - 1 : high);
|
||||||
struct type *elt_type = ada_array_element_type (arr_type0, 1);
|
struct type *elt_type = ada_array_element_type (arr_type0, 1);
|
||||||
|
|
||||||
return allocate_value (create_array_type (NULL, elt_type, index_type));
|
return allocate_value (create_array_type (NULL, elt_type, index_type));
|
||||||
|
@ -11033,7 +11035,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
|
||||||
if (noside == EVAL_AVOID_SIDE_EFFECTS
|
if (noside == EVAL_AVOID_SIDE_EFFECTS
|
||||||
&& ada_is_array_descriptor_type (ada_check_typedef
|
&& ada_is_array_descriptor_type (ada_check_typedef
|
||||||
(value_type (array))))
|
(value_type (array))))
|
||||||
return empty_array (ada_type_of_array (array, 0), low_bound);
|
return empty_array (ada_type_of_array (array, 0), low_bound,
|
||||||
|
high_bound);
|
||||||
|
|
||||||
array = ada_coerce_to_simple_array_ptr (array);
|
array = ada_coerce_to_simple_array_ptr (array);
|
||||||
|
|
||||||
|
@ -11057,7 +11060,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
|
||||||
struct type *type0 = ada_check_typedef (value_type (array));
|
struct type *type0 = ada_check_typedef (value_type (array));
|
||||||
|
|
||||||
if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
|
if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
|
||||||
return empty_array (TYPE_TARGET_TYPE (type0), low_bound);
|
return empty_array (TYPE_TARGET_TYPE (type0), low_bound, high_bound);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct type *arr_type0 =
|
struct type *arr_type0 =
|
||||||
|
@ -11071,7 +11074,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
|
||||||
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
||||||
return array;
|
return array;
|
||||||
else if (high_bound < low_bound)
|
else if (high_bound < low_bound)
|
||||||
return empty_array (value_type (array), low_bound);
|
return empty_array (value_type (array), low_bound, high_bound);
|
||||||
else
|
else
|
||||||
return ada_value_slice (array, longest_to_int (low_bound),
|
return ada_value_slice (array, longest_to_int (low_bound),
|
||||||
longest_to_int (high_bound));
|
longest_to_int (high_bound));
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
2019-03-18 Joel Brobecker <brobecker@adacore.com>
|
||||||
|
Tom Tromey <tromey@adacore.com>
|
||||||
|
|
||||||
|
* gdb.ada/ptype_array/pck.adb: New file.
|
||||||
|
* gdb.ada/ptype_array/pck.ads: New file.
|
||||||
|
* gdb.ada/ptype_array/foo.adb: New file.
|
||||||
|
* gdb.ada/ptype_array.exp: New file.
|
||||||
|
|
||||||
2019-03-14 Tom Tromey <tromey@adacore.com>
|
2019-03-14 Tom Tromey <tromey@adacore.com>
|
||||||
|
|
||||||
* gdb.base/style.exp: Add "set style sources" test.
|
* gdb.base/style.exp: Add "set style sources" test.
|
||||||
|
|
34
gdb/testsuite/gdb.ada/ptype_array.exp
Normal file
34
gdb/testsuite/gdb.ada/ptype_array.exp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# Copyright 2019 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 additional_flags=-gnat05 ]] != "" } {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_restart ${testfile}
|
||||||
|
|
||||||
|
runto_main
|
||||||
|
|
||||||
|
gdb_test "ptype pck.W.G(1,5).m(2 .. 5)" \
|
||||||
|
"type = array \\(2 \\.\\. 5\\) of character" \
|
||||||
|
"ptype 2..5"
|
||||||
|
|
||||||
|
gdb_test "ptype pck.W.G(1,5).m(3 .. 5)" \
|
||||||
|
"type = array \\(3 \\.\\. 5\\) of character" \
|
||||||
|
"ptype 3..5"
|
21
gdb/testsuite/gdb.ada/ptype_array/foo.adb
Normal file
21
gdb/testsuite/gdb.ada/ptype_array/foo.adb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
-- Copyright 2019 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;
|
||||||
|
|
||||||
|
procedure Foo is
|
||||||
|
begin
|
||||||
|
Pck.Do_Nothing (Pck.W.G'Address);
|
||||||
|
end Foo;
|
23
gdb/testsuite/gdb.ada/ptype_array/pck.adb
Normal file
23
gdb/testsuite/gdb.ada/ptype_array/pck.adb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
-- Copyright 2019 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;
|
||||||
|
|
||||||
|
|
30
gdb/testsuite/gdb.ada/ptype_array/pck.ads
Normal file
30
gdb/testsuite/gdb.ada/ptype_array/pck.ads
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
-- Copyright 2019 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
|
||||||
|
package W is
|
||||||
|
type P is record
|
||||||
|
M : String (2 .. 5);
|
||||||
|
end record;
|
||||||
|
|
||||||
|
type R is array (1 .. 10, 1 .. 20) of P;
|
||||||
|
|
||||||
|
G : R;
|
||||||
|
end W;
|
||||||
|
|
||||||
|
procedure Do_Nothing (A : System.Address);
|
||||||
|
end Pck;
|
Loading…
Add table
Add a link
Reference in a new issue