public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix bug in Ada packed array handling
@ 2022-10-21 15:52 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-10-21 15:52 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6c849804cff9e251876f3edb64d44dabeadaa711
commit 6c849804cff9e251876f3edb64d44dabeadaa711
Author: Tom Tromey <tromey@adacore.com>
Date: Tue Sep 20 08:39:09 2022 -0600
Fix bug in Ada packed array handling
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.
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 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;
}
@@ -15701,11 +15702,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 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 () == 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 19700a7153e..7b10c8448e6 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -927,6 +927,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. */
@@ -1350,6 +1359,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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-21 15:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 15:52 [binutils-gdb] Fix bug in Ada packed array handling Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).