From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id 5BE3A3858C2F for ; Tue, 5 Jul 2022 16:41:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5BE3A3858C2F Received: by mail-io1-xd35.google.com with SMTP id p69so11618270iod.10 for ; Tue, 05 Jul 2022 09:41:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MMMmhpQJOtXv9h4SZ78SZm9goVlgpCX4kXyehpupvaw=; b=aU6WzQu7RoMYQWoM/V0vc1yQC7YFxB6b9Zk2tiyb8BhjqlWqaQNXJ4XK/dH7LOZYzi F+ySp5Pv++C+bWCfBB6+Q/0kLuWHPC4T+/JhXGBIxZCy9/Nn/DcVwWE4wK/xG/f1b+2R 5HLDo5cDyq/j7pM0MVWqGWRiR0ZHLNqAXeQOtL1rJZMW9N8ErX01HWgn/52V5oMmWsil xTNsuHaZ7XOKRcwKDMZ+aXLSla471HyiwOCKUlUDetjrFmdztS1skFKuhEJ5bNUUOWBL WcGPxC8JtLHQzP5gW0vLBDqMwqJFoH3gZ3Za/2aAy0bdG+7NkKmCmRKWzweKv3fggMaa nnwg== X-Gm-Message-State: AJIora/0AUYwjoPzPUjvBY33mPZT2/TUbrShPFkn3IjXIkafgqj3cqd8 K6nAErEGReerkp9wpDCLRDyVvQjJHL3dSg== X-Google-Smtp-Source: AGRyM1sRCQ8N4meYKbmorE4Od9PNzB10GTlTXOWIxW1l8i+3mDy7L9Gh2YEgXon8qjzgL0ly1yb+Yg== X-Received: by 2002:a05:6638:41a8:b0:33c:d315:ad82 with SMTP id az40-20020a05663841a800b0033cd315ad82mr21270799jab.269.1657039282274; Tue, 05 Jul 2022 09:41:22 -0700 (PDT) Received: from murgatroyd.Home (71-211-187-180.hlrn.qwest.net. [71.211.187.180]) by smtp.gmail.com with ESMTPSA id s10-20020a5ec64a000000b0067520155dedsm13835851ioo.15.2022.07.05.09.41.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jul 2022 09:41:21 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove array typedef assumption for Ada Date: Tue, 5 Jul 2022 10:41:20 -0600 Message-Id: <20220705164120.3356777-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 16:41:26 -0000 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. A planned compiler change will remove this typedef, which causes a gdb failure in the internal AdaCore test suite. This patch handles this case by checking whether the array type in question has a name. --- 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(-) create mode 100644 gdb/testsuite/gdb.ada/multiarray.exp create mode 100644 gdb/testsuite/gdb.ada/multiarray/p.adb create mode 100644 gdb/testsuite/gdb.ada/multiarray/pack.ads 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 nindices) while (nindices != 0 && type->code () == TYPE_CODE_ARRAY) { type = 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 () != nullptr) + break; nindices -= 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 *stream, int show, bitsize = 0; if (range_desc_type == NULL) { - for (arr_type = type; arr_type->code () == TYPE_CODE_ARRAY; - arr_type = TYPE_TARGET_TYPE (arr_type)) + for (arr_type = type; arr_type->code () == TYPE_CODE_ARRAY; ) { if (arr_type != type) gdb_printf (stream, ", "); @@ -386,6 +385,14 @@ print_array_type (struct type *type, struct ui_file *stream, int show, 0 /* bounds_prefered_p */); if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0) bitsize = 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 = TYPE_TARGET_TYPE (arr_type); + if (arr_type->name () != nullptr) + break; } } else diff --git a/gdb/testsuite/gdb.ada/multiarray.exp b/gdb/testsuite/gdb.ada/multiarray.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=-fgnat-encodings=$scenario] + + if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + 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 = array (<>, <>) of integer"] + gdb_test "ptype nested_type" \ + [string_to_regexp "type = array (<>, <>) of pack.ca_simple_type"] + + gdb_test "ptype simple" \ + [string_to_regexp "type = array (1 .. 3, 5 .. 6) of integer"] + gdb_test "ptype nested" \ + [string_to_regexp "type = array (1 .. 3, 5 .. 6) of pack.ca_simple_type"] + + gdb_test "print simple" \ + [string_to_regexp " = ((5 => 1, 2), (5 => 3, 4), (5 => 5, 6))"] + gdb_test "print nested" \ + [string_to_regexp " = ((5 => (1, 2), (3, 4)), (5 => (5, 6), (7, 8)), (5 => (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 := + (1 => (5 => 1, 6 => 2), + 2 => (5 => 3, 6 => 4), + 3 => (5 => 5, 6 => 6)); + Nested : Nested_Type := + (1 => (5 => (1, 2), 6 => (3, 4)), + 2 => (5 => (5, 6), 6 => (7, 8)), + 3 => (5 => (9, 10), 6 => (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; -- 2.34.1