From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id B0EC53856DC0; Fri, 21 Oct 2022 15:52:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0EC53856DC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666367559; bh=H8fFFZ6HCHiFqgvOJSW5RLzXQzEZ2UWA4w3yzYjFukA=; h=From:To:Subject:Date:From; b=QrUCtkehukj7yCFsi6X/Zq7/F0m9SEmovxMcFk0+u3oHWZgKUFhifiqAdMsct9Ns6 DTbRuhPcKhQwjQAIkhiH1OroUtWa7HP48DruxB1TekG0ANXW06fs9nOrryTzafKUuX 38EvgnLnkctUlSqMS9w0EE9W7og+A6X+k84LxRow= 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] Fix bug in Ada packed array handling X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 75436c534bfd7f548a13b5f926c3bd234b23b8d0 X-Git-Newrev: 6c849804cff9e251876f3edb64d44dabeadaa711 Message-Id: <20221021155239.B0EC53856DC0@sourceware.org> Date: Fri, 21 Oct 2022 15:52:39 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6c849804cff9= e251876f3edb64d44dabeadaa711 commit 6c849804cff9e251876f3edb64d44dabeadaa711 Author: Tom Tromey Date: Tue Sep 20 08:39:09 2022 -0600 Fix bug in Ada packed array handling =20 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. =20 This patch fixes the problem by adding a flag to indicate whether a given array type is a constituent of a multi-dimensional array. Diff: --- 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 89ba9122e91..7de89dd5923 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15690,6 +15690,7 @@ read_array_type (struct die_info *die, struct dwarf= 2_cu *cu) { type =3D create_array_type_with_stride (NULL, type, range_types[i++], byte_stride_prop, bit_stride); + type->set_is_multi_dimensional (true); bit_stride =3D 0; byte_stride_prop =3D nullptr; } @@ -15701,11 +15702,14 @@ read_array_type (struct die_info *die, struct dwa= rf2_cu *cu) { type =3D create_array_type_with_stride (NULL, type, range_types[ndim], byte_stride_prop, bit_stride); + type->set_is_multi_dimensional (true); bit_stride =3D 0; byte_stride_prop =3D nullptr; } } =20 + /* Clear the flag on the outermost array type. */ + type->set_is_multi_dimensional (false); gdb_assert (type !=3D element_type); =20 /* Understand Dwarf2 support for vector types (like they occur on diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index ecccaf77405..a43d9265ad2 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 () =3D=3D TYPE_CODE_ARRAY + && (stride !=3D 0 || element_type->is_multi_dimensional ()) && element_type->length () !=3D 0 && TYPE_FIELD_BITSIZE (element_type, 0) !=3D 0 && get_array_bounds (element_type, &low_bound, &high_bound) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 19700a7153e..7b10c8448e6 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -927,6 +927,15 @@ struct main_type =20 unsigned int m_flag_flag_enum : 1; =20 + /* * 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. */ =20 @@ -1350,6 +1359,18 @@ struct type this->main_type->m_flag_flag_enum =3D is_flag_enum; } =20 + /* 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 =3D value; + } + /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference to this type's fixed_point_info. */ =20 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 =3D> true, false, true, false, true)" + gdb_test "print o_var" \ + [string_to_regexp " =3D ($line, $line, $line, $line)"] + gdb_test "print o2_var" \ + [string_to_regexp " =3D ($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 =20 U_Var : Unconstrained_Packed_Array (1 .. Ident (6)); =20 + -- Note that this array is not packed. + type Outer_Array is array (1 .. 4) of Packed_Array; + O_Var : Outer_Array :=3D ((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 :=3D ((true, false, true, false, true), + (true, false, true, false, true), + (true, false, true, false, true), + (true, false, true, false, true)); + begin =20 Var :=3D (True, False, True, False, True);