From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uAd8I1XldF+XdgAAWB0awg (envelope-from ) for ; Wed, 30 Sep 2020 16:06:45 -0400 Received: by simark.ca (Postfix, from userid 112) id 7E3161EF79; Wed, 30 Sep 2020 16:06:45 -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 C962A1EF44 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 E54CC39878EF; 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 634673857C50 for ; Wed, 30 Sep 2020 20:06:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 634673857C50 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 07B991175D2; Wed, 30 Sep 2020 16:06:07 -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 eKV-MuaLvkjr; 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 B8F2B1175B8; Wed, 30 Sep 2020 16:06:06 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 6/9] Fix bit strides for -fgnat-encodings=minimal Date: Wed, 30 Sep 2020 14:05:57 -0600 Message-Id: <20200930200600.1207702-7-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" With -fgnat-encodings=minimal, the enum_idx_packed.exp test will fail. In this test case, we have an array (with dynamic length) of arrays, and the inner array has a bit stride. In this situation, the outer array's bit stride must be updated to account for the entire bit length of the inner array. Here, again, some tests must be kfail'd when an older version of GNAT is in use. gdb/ChangeLog 2020-09-30 Tom Tromey * gdbtypes.c (update_static_array_size): Handle bit stride. gdb/testsuite/ChangeLog 2020-09-30 Tom Tromey * gdb.ada/enum_idx_packed.exp: Test two forms of -fgnat-encodings. --- gdb/ChangeLog | 4 + gdb/gdbtypes.c | 14 +++ gdb/testsuite/ChangeLog | 4 + gdb/testsuite/gdb.ada/enum_idx_packed.exp | 121 ++++++++++++++-------- 4 files changed, 102 insertions(+), 41 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 43c05d344d0..872a23ea497 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1235,6 +1235,20 @@ update_static_array_size (struct type *type) TYPE_LENGTH (type) = TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); + /* If this array's element is itself an array with a bit stride, + then we want to update this array's bit stride to reflect the + size of the sub-array. Otherwise, we'll end up using the + wrong size when trying to find elements of the outer + array. */ + if (element_type->code () == TYPE_CODE_ARRAY + && TYPE_LENGTH (element_type) != 0 + && TYPE_FIELD_BITSIZE (element_type, 0) != 0 + && get_array_bounds (element_type, &low_bound, &high_bound) >= 0 + && high_bound >= low_bound) + TYPE_FIELD_BITSIZE (type, 0) + = ((high_bound - low_bound + 1) + * TYPE_FIELD_BITSIZE (element_type, 0)); + return true; } diff --git a/gdb/testsuite/gdb.ada/enum_idx_packed.exp b/gdb/testsuite/gdb.ada/enum_idx_packed.exp index 480de71b7c4..91859689c4a 100644 --- a/gdb/testsuite/gdb.ada/enum_idx_packed.exp +++ b/gdb/testsuite/gdb.ada/enum_idx_packed.exp @@ -19,64 +19,103 @@ if { [skip_ada_tests] } { return -1 } standard_ada_testfile foo -if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { - return -1 -} +foreach_with_prefix scenario {all minimal} { + set flags [list debug additional_flags=-fgnat-encodings=$scenario] -clean_restart ${testfile} + if {[gdb_compile_ada "${srcfile}" "${binfile}" executable $flags] != ""} { + return -1 + } -set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb] -runto "foo.adb:$bp_location" + clean_restart ${testfile} -gdb_test "ptype full" \ - "type = array \\(black \\.\\. white\\) of boolean " + # GNAT >= 11.0 has the needed fix here. + if {$scenario == "minimal" && ![test_compiler_info {gcc-1[1-9]-*}]} { + set old_compiler 1 + } else { + set old_compiler 0 + } -gdb_test "print full" " = \\(false, true, false, true, false\\)" + set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb] + runto "foo.adb:$bp_location" -gdb_test "print full'first" " = black" + gdb_test "ptype full" \ + "type = array \\(black \\.\\. white\\) of boolean " -gdb_test "ptype primary" \ - "type = array \\(red \\.\\. blue\\) of boolean " + gdb_test "print full" " = \\(false, true, false, true, false\\)" -gdb_test "print primary" " = \\(red => false, true, false\\)" + gdb_test "print full'first" " = black" -gdb_test "print primary'first" " = red" + gdb_test "ptype primary" \ + "type = array \\(red \\.\\. blue\\) of boolean " -gdb_test "ptype cold" \ - "type = array \\(green \\.\\. blue\\) of boolean " + gdb_test "print primary" " = \\(red => false, true, false\\)" -gdb_test "print cold" " = \\(green => false, true\\)" + gdb_test "print primary'first" " = red" -gdb_test "print cold'first" " = green" + gdb_test "ptype cold" \ + "type = array \\(green \\.\\. blue\\) of boolean " -# Note the bounds values are still not correctly displayed. So we get -# the enum equivalent of "1 .. 0" (empty range) as the array ranges. -# Accept that for now. -gdb_test "ptype small" \ - "array \\(red \\.\\. green\\) of boolean " + gdb_test "print cold" " = \\(green => false, true\\)" -gdb_test "print small" " = \\(red => false, true\\)" + gdb_test "print cold'first" " = green" -gdb_test "print small'first" " = red" + # Note the bounds values are still not correctly displayed. So we get + # the enum equivalent of "1 .. 0" (empty range) as the array ranges. + # Accept that for now. + # GNAT >= 11.0 has the needed fix here. + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "ptype small" \ + "array \\(red \\.\\. green\\) of boolean " -gdb_test "ptype multi" \ - "array \\(red \\.\\. green, low .. medium\\) of boolean " + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "print small" " = \\(red => false, true\\)" -gdb_test "print multi" \ - " = \\(red => \\(low => true, false\\), \\(low => true, false\\)\\)" + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "print small'first" " = red" -gdb_test "print multi'first" " = red" + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "ptype multi" \ + "array \\(red \\.\\. green, low .. medium\\) of boolean " -set base "\\(true, false, true, false, true, false, true, false, true, false\\)" -set matrix "\\(" -foreach x {1 2 3 4 5 6 7} { - if {$x > 1} { - append matrix ", " + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* } - append matrix $base -} -append matrix "\\)" + gdb_test "print multi" \ + " = \\(red => \\(low => true, false\\), \\(low => true, false\\)\\)" -gdb_test "print multi_multi" " = \\($matrix, $matrix\\)" -gdb_test "print multi_multi(1,3)" " = $base" -gdb_test "print multi_multi(2)" " = $matrix" + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "print multi'first" " = red" + + set base "\\(true, false, true, false, true, false, true, false, true, false\\)" + set matrix "\\(" + foreach x {1 2 3 4 5 6 7} { + if {$x > 1} { + append matrix ", " + } + append matrix $base + } + append matrix "\\)" + + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "print multi_multi" " = \\($matrix, $matrix\\)" + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "print multi_multi(1,3)" " = $base" + if {$old_compiler} { + setup_kfail "minimal encodings" *-*-* + } + gdb_test "print multi_multi(2)" " = $matrix" +} -- 2.26.2