aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-09-20 08:39:09 -0600
committerTom Tromey <tromey@adacore.com>2022-10-21 09:40:58 -0600
commit6c849804cff9e251876f3edb64d44dabeadaa711 (patch)
treeda7aa69ba5cb2c894a91ba814eb256293c95cde9 /gdb
parent75436c534bfd7f548a13b5f926c3bd234b23b8d0 (diff)
downloadgdb-6c849804cff9e251876f3edb64d44dabeadaa711.zip
gdb-6c849804cff9e251876f3edb64d44dabeadaa711.tar.gz
gdb-6c849804cff9e251876f3edb64d44dabeadaa711.tar.bz2
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.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/dwarf2/read.c4
-rw-r--r--gdb/gdbtypes.c1
-rw-r--r--gdb/gdbtypes.h21
-rw-r--r--gdb/testsuite/gdb.ada/packed_array.exp6
-rw-r--r--gdb/testsuite/gdb.ada/packed_array/pa.adb14
5 files changed, 46 insertions, 0 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 89ba912..7de89dd 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 ecccaf7..a43d926 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 19700a7..7b10c84 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 eb857f7..df34f31 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 2955f98..bb6a2ac 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);