From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 3419738A284E for ; Thu, 6 Oct 2022 20:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3419738A284E Received: by mail-il1-x136.google.com with SMTP id r20so1539950ilt.11 for ; Thu, 06 Oct 2022 13:06:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UftGQtDXWHlavoNODwUmGAis2AQS+O8stT+1mWfh9ls=; b=tsbK1UXF7GRKt1/KnQhe4u0haeJ5mon+XAruAlQ74m8ikCmgPq8Vh4b4hf9taMiMkm i8BE1wGOXiXBzWlBYN5crHByazrnPAv05XxZD8FxNMmKIXqrjyFl7N7JPrEwqpGTnctw UODoYOr36mIKzp6hmARk4uzzpEA58JZRRExvbXYINkErv3Jz8v5tGw0FaGIKAPJccSuA LvKw33hxIAhohCReT3hpC1AiZYxLpqGtEieMBKRXSA0EUKjXFRs7Z6ordXZx87xGSja6 R4V3vVH2VLj1AzfyK1CnqUrsh0yIdJxLOy22GhSx/QekgbkGcftgJFT2XamMFFeQaUhA aeXw== X-Gm-Message-State: ACrzQf2s7zwds7Ri3s/6vbQ85kMYauLrKhk+cP8gpgly1PzVlenIm9vZ l4lb2O4Tmx33CApXpwfPJy2CJzZQxNVRZg== X-Google-Smtp-Source: AMsMyM5sQslvcOpCBz41QeBrNr63cMUTYKcTzPamZX3EiD+kKFVjN6MShAUJAvPG72ZGJjHULJvCsw== X-Received: by 2002:a05:6e02:19c8:b0:2fa:a5c2:f837 with SMTP id r8-20020a056e0219c800b002faa5c2f837mr667960ill.1.1665086781516; Thu, 06 Oct 2022 13:06:21 -0700 (PDT) Received: from localhost.localdomain (71-211-160-49.hlrn.qwest.net. [71.211.160.49]) by smtp.gmail.com with ESMTPSA id bp12-20020a056638440c00b0035a468b7fbesm122847jab.71.2022.10.06.13.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 13:06:21 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] Fix bug in Ada packed array handling Date: Thu, 6 Oct 2022 14:06:09 -0600 Message-Id: <20221006200610.3678399-2-tromey@adacore.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20221006200610.3678399-1-tromey@adacore.com> References: <20221006200610.3678399-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: Thu, 06 Oct 2022 20:06:24 -0000 A user found a bug where an array of packed arrays was printed incorrectly. The bug here is that the packed array has a bit stride, but the outer array does not -- and should not. However, update_static_array_size does not distinguish between an array of packed arrays and a multi-dimensional packed array, and for the latter, only the innermost array will end up with a stride. This patch fixes the problem by adding a flag to indicate whether a given array type is a constituent of a multi-dimensional array. --- gdb/dwarf2/read.c | 4 ++++ gdb/gdbtypes.c | 1 + gdb/gdbtypes.h | 21 +++++++++++++++++++++ gdb/testsuite/gdb.ada/packed_array.exp | 6 ++++++ gdb/testsuite/gdb.ada/packed_array/pa.adb | 14 ++++++++++++++ 5 files changed, 46 insertions(+) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 78f4cc1f60d..116fc59821a 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15695,6 +15695,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) { type = create_array_type_with_stride (NULL, type, range_types[i++], byte_stride_prop, bit_stride); + type->set_is_multi_dimensional (true); bit_stride = 0; byte_stride_prop = nullptr; } @@ -15706,11 +15707,14 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) { type = create_array_type_with_stride (NULL, type, range_types[ndim], byte_stride_prop, bit_stride); + type->set_is_multi_dimensional (true); bit_stride = 0; byte_stride_prop = nullptr; } } + /* Clear the flag on the outermost array type. */ + type->set_is_multi_dimensional (false); gdb_assert (type != element_type); /* Understand Dwarf2 support for vector types (like they occur on diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 643bb0a14a3..9ddb1f81cc1 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1319,6 +1319,7 @@ update_static_array_size (struct type *type) wrong size when trying to find elements of the outer array. */ if (element_type->code () == TYPE_CODE_ARRAY + && (stride != 0 || element_type->is_multi_dimensional ()) && element_type->length () != 0 && TYPE_FIELD_BITSIZE (element_type, 0) != 0 && get_array_bounds (element_type, &low_bound, &high_bound) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 94d4b6684fb..f92b3894a1b 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -926,6 +926,15 @@ struct main_type unsigned int m_flag_flag_enum : 1; + /* * For TYPE_CODE_ARRAY, this is true if this type is part of a + multi-dimensional array. Multi-dimensional arrays are + represented internally as arrays of arrays, and this flag lets + gdb distinguish between multiple dimensions and an ordinary array + of arrays. The flag is set on each inner dimension, but not the + outermost dimension. */ + + unsigned int m_multi_dimensional : 1; + /* * A discriminant telling us which field of the type_specific union is being used for this type, if any. */ @@ -1349,6 +1358,18 @@ struct type this->main_type->m_flag_flag_enum = is_flag_enum; } + /* True if this array type is part of a multi-dimensional array. */ + + bool is_multi_dimensional () const + { + return this->main_type->m_multi_dimensional; + } + + void set_is_multi_dimensional (bool value) + { + this->main_type->m_multi_dimensional = value; + } + /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference to this type's fixed_point_info. */ diff --git a/gdb/testsuite/gdb.ada/packed_array.exp b/gdb/testsuite/gdb.ada/packed_array.exp index eb857f7e564..df34f31348a 100644 --- a/gdb/testsuite/gdb.ada/packed_array.exp +++ b/gdb/testsuite/gdb.ada/packed_array.exp @@ -57,4 +57,10 @@ foreach_with_prefix scenario {all minimal} { xfail $test } } + + set line "(4 => true, false, true, false, true)" + gdb_test "print o_var" \ + [string_to_regexp " = ($line, $line, $line, $line)"] + gdb_test "print o2_var" \ + [string_to_regexp " = ($line, $line, $line, $line)"] } diff --git a/gdb/testsuite/gdb.ada/packed_array/pa.adb b/gdb/testsuite/gdb.ada/packed_array/pa.adb index 2955f986b00..bb6a2acd388 100644 --- a/gdb/testsuite/gdb.ada/packed_array/pa.adb +++ b/gdb/testsuite/gdb.ada/packed_array/pa.adb @@ -27,6 +27,20 @@ procedure PA is U_Var : Unconstrained_Packed_Array (1 .. Ident (6)); + -- Note that this array is not packed. + type Outer_Array is array (1 .. 4) of Packed_Array; + O_Var : Outer_Array := ((true, false, true, false, true), + (true, false, true, false, true), + (true, false, true, false, true), + (true, false, true, false, true)); + + type Outer_Array2 is array (1 .. 4) of Packed_Array; + pragma pack (Outer_Array2); + O2_Var : Outer_Array2 := ((true, false, true, false, true), + (true, false, true, false, true), + (true, false, true, false, true), + (true, false, true, false, true)); + begin Var := (True, False, True, False, True); -- 2.34.3