From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 1C26C3852761; Mon, 18 Jul 2022 15:57:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C26C3852761 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Remove array typedef assumption for Ada X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 083aca0c8333fc24c6a65a03fca765bc13ee37c0 X-Git-Newrev: 6a40c6e4374a660eab5cdc2f8a777ccbd7a81951 Message-Id: <20220718155728.1C26C3852761@sourceware.org> Date: Mon, 18 Jul 2022 15:57:28 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2022 15:57:28 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6a40c6e4374a= 660eab5cdc2f8a777ccbd7a81951 commit 6a40c6e4374a660eab5cdc2f8a777ccbd7a81951 Author: Tom Tromey Date: Fri Jun 17 07:41:37 2022 -0600 Remove array typedef assumption for Ada =20 Currently the Ada code assumes that it can distinguish between a multi-dimensional array and an array of arrays by looking for an intervening typedef -- that is, for an array of arrays, there will be a typedef wrapping the innermost array type. =20 A recent compiler change removes this typedef, which causes a gdb failure in the internal AdaCore test suite. =20 This patch handles this case by checking whether the array type in question has a name. Diff: --- gdb/ada-lang.c | 6 ++++ gdb/ada-typeprint.c | 11 +++++-- gdb/testsuite/gdb.ada/multiarray.exp | 48 +++++++++++++++++++++++++++= ++++ gdb/testsuite/gdb.ada/multiarray/p.adb | 46 +++++++++++++++++++++++++++= ++ gdb/testsuite/gdb.ada/multiarray/pack.ads | 34 ++++++++++++++++++++++ 5 files changed, 143 insertions(+), 2 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 93e0c67613f..650408134bb 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3208,6 +3208,12 @@ ada_array_element_type (struct type *type, int nindi= ces) while (nindices !=3D 0 && type->code () =3D=3D TYPE_CODE_ARRAY) { type =3D TYPE_TARGET_TYPE (type); + /* A multi-dimensional array is represented using a sequence + of array types. If one of these types has a name, then + it is not another dimension of the outer array, but + rather the element type of the outermost array. */ + if (type->name () !=3D nullptr) + break; nindices -=3D 1; } return type; diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c index 05ffb8b8331..b402bfef523 100644 --- a/gdb/ada-typeprint.c +++ b/gdb/ada-typeprint.c @@ -377,8 +377,7 @@ print_array_type (struct type *type, struct ui_file *st= ream, int show, bitsize =3D 0; if (range_desc_type =3D=3D NULL) { - for (arr_type =3D type; arr_type->code () =3D=3D TYPE_CODE_ARRAY; - arr_type =3D TYPE_TARGET_TYPE (arr_type)) + for (arr_type =3D type; arr_type->code () =3D=3D TYPE_CODE_ARRAY; ) { if (arr_type !=3D type) gdb_printf (stream, ", "); @@ -386,6 +385,14 @@ print_array_type (struct type *type, struct ui_file *s= tream, int show, 0 /* bounds_prefered_p */); if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0) bitsize =3D TYPE_FIELD_BITSIZE (arr_type, 0); + /* A multi-dimensional array is represented using a + sequence of array types. If one of these types has a + name, then it is not another dimension of the outer + array, but rather the element type of the outermost + array. */ + arr_type =3D TYPE_TARGET_TYPE (arr_type); + if (arr_type->name () !=3D nullptr) + break; } } else diff --git a/gdb/testsuite/gdb.ada/multiarray.exp b/gdb/testsuite/gdb.ada/m= ultiarray.exp new file mode 100644 index 00000000000..bac16f2eee5 --- /dev/null +++ b/gdb/testsuite/gdb.ada/multiarray.exp @@ -0,0 +1,48 @@ +# Copyright 2022 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 . + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile p + +foreach_with_prefix scenario {all minimal} { + set flags [list debug additional_flags=3D-fgnat-encodings=3D$scenario] + + if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != =3D ""} { + return -1 + } + + clean_restart ${testfile} + + set bp_location [gdb_get_line_number "START" ${testdir}/p.adb] + runto "p.adb:$bp_location" + + gdb_test "ptype simple_type" \ + [string_to_regexp "type =3D array (<>, <>) of integer"] + gdb_test "ptype nested_type" \ + [string_to_regexp "type =3D array (<>, <>) of pack.ca_simple_type"] + + gdb_test "ptype simple" \ + [string_to_regexp "type =3D array (1 .. 3, 5 .. 6) of integer"] + gdb_test "ptype nested" \ + [string_to_regexp "type =3D array (1 .. 3, 5 .. 6) of pack.ca_simple_type= "] + + gdb_test "print simple" \ + [string_to_regexp " =3D ((5 =3D> 1, 2), (5 =3D> 3, 4), (5 =3D> 5, 6))"] + gdb_test "print nested" \ + [string_to_regexp " =3D ((5 =3D> (1, 2), (3, 4)), (5 =3D> (5, 6), (7, 8))= , (5 =3D> (9, 10), (11, 12)))"] +} diff --git a/gdb/testsuite/gdb.ada/multiarray/p.adb b/gdb/testsuite/gdb.ada= /multiarray/p.adb new file mode 100644 index 00000000000..eacc4063a90 --- /dev/null +++ b/gdb/testsuite/gdb.ada/multiarray/p.adb @@ -0,0 +1,46 @@ +-- Copyright 2022 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 . + +with Pack; use Pack; + +procedure P is + + procedure Nop is + begin + null; + end Nop; + + procedure Discard + (Arg_Simple : Simple_Type; + Arg_Nested : Nested_Type) is + begin + null; + end Discard; + + Simple : Simple_Type :=3D + (1 =3D> (5 =3D> 1, 6 =3D> 2), + 2 =3D> (5 =3D> 3, 6 =3D> 4), + 3 =3D> (5 =3D> 5, 6 =3D> 6)); + Nested : Nested_Type :=3D + (1 =3D> (5 =3D> (1, 2), 6 =3D> (3, 4)), + 2 =3D> (5 =3D> (5, 6), 6 =3D> (7, 8)), + 3 =3D> (5 =3D> (9, 10), 6 =3D> (11, 12))); + +begin + Nop; -- START + + Discard (Simple, Nested); + +end P; diff --git a/gdb/testsuite/gdb.ada/multiarray/pack.ads b/gdb/testsuite/gdb.= ada/multiarray/pack.ads new file mode 100644 index 00000000000..06091dea6a0 --- /dev/null +++ b/gdb/testsuite/gdb.ada/multiarray/pack.ads @@ -0,0 +1,34 @@ +-- Copyright 2022 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 . + +package Pack is + + type Index_Type_1 is new Natural; + type Index_Type_2 is new Natural; + type Index_Type_3 is new Natural; + + type CA_Simple_Type is array (Index_Type_1 range 1 .. 2) of Integer; + + -- Array types we test + + type Simple_Type is + array (Index_Type_1 range <>, Index_Type_2 range <>) + of Integer; + + type Nested_Type is + array (Index_Type_1 range <>, Index_Type_2 range <>) + of CA_Simple_Type; + +end Pack;