From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WDdxHVHldF91dgAAWB0awg (envelope-from ) for ; Wed, 30 Sep 2020 16:06:41 -0400 Received: by simark.ca (Postfix, from userid 112) id 76C811E99A; Wed, 30 Sep 2020 16:06:41 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 38DA41E99A for ; Wed, 30 Sep 2020 16:06:40 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97D5F3987802; Wed, 30 Sep 2020 20:06:39 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 8ADA13972019 for ; Wed, 30 Sep 2020 20:06:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8ADA13972019 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5FED6116F1D; Wed, 30 Sep 2020 16:06:06 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 315uhjzFOA-X; Wed, 30 Sep 2020 16:06:06 -0400 (EDT) Received: from murgatroyd.Home (97-118-100-18.hlrn.qwest.net [97.118.100.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 1DA6E1175B8; Wed, 30 Sep 2020 16:06:06 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 4/9] Reject slicing a packed array Date: Wed, 30 Sep 2020 14:05:55 -0600 Message-Id: <20200930200600.1207702-5-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930200600.1207702-1-tromey@adacore.com> References: <20200930200600.1207702-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" In Ada mode, gdb rejects slicing a packed array. However, with -fgnat-encodings=minimal, gdb will instead print incorrect results. This patch changes gdb to also reject slicing a packed array in this mode. FWIW I believe that this rejection is a gdb limitation. Removing it looked complicated, though, and meanwhile my main goal for the time being is to bring the DWARF encodings up to par with Gnat encodings. 2020-09-30 Tom Tromey * ada-lang.c (ada_is_any_packed_array_type): New function. (ada_evaluate_subexp) : Use it. gdb/testsuite/ChangeLog 2020-09-30 Tom Tromey * gdb.ada/mod_from_name.exp: Test printing slice. --- gdb/ChangeLog | 5 +++++ gdb/ada-lang.c | 13 ++++++++++++- gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.ada/mod_from_name.exp | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c7eabbef2ae..d851f57414b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2030,6 +2030,17 @@ ada_is_unconstrained_packed_array_type (struct type *type) return 0; } +/* Return true if TYPE is a (Gnat-encoded) constrained packed array + type, or if it is an ordinary (non-Gnat-encoded) packed array. */ + +static bool +ada_is_any_packed_array_type (struct type *type) +{ + return (ada_is_constrained_packed_array_type (type) + || (type->code () == TYPE_CODE_ARRAY + && TYPE_FIELD_BITSIZE (type, 0) % 8 != 0)); +} + /* Given that TYPE encodes a packed array type (constrained or unconstrained), return the size of its elements in bits. */ @@ -10626,7 +10637,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, TYPE_TARGET_TYPE (value_type (array)) = ada_aligned_type (TYPE_TARGET_TYPE (value_type (array))); - if (ada_is_constrained_packed_array_type (value_type (array))) + if (ada_is_any_packed_array_type (value_type (array))) error (_("cannot slice a packed array")); /* If this is a reference to an array or an array lvalue, diff --git a/gdb/testsuite/gdb.ada/mod_from_name.exp b/gdb/testsuite/gdb.ada/mod_from_name.exp index fec383bb490..43d81e0026f 100644 --- a/gdb/testsuite/gdb.ada/mod_from_name.exp +++ b/gdb/testsuite/gdb.ada/mod_from_name.exp @@ -40,4 +40,5 @@ foreach_with_prefix scenario {all minimal} { } gdb_test "print xp" \ "= \\(y => \\(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10\\)\\)" + gdb_test "print slice" "cannot slice a packed array" } -- 2.26.2