From 7ff5b9370f4f7c0c75d734aa19b8f020429d4bb5 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 4 Nov 2020 08:49:16 -0700 Subject: Use bit stride when taking slice of array Testing with -fgnat-encodings=minimal showed that the Ada code failed to use the bit stride of an array when taking a slice. This patch fixes the oversight. gdb/ChangeLog 2020-11-04 Tom Tromey * ada-lang.c (ada_value_slice_from_ptr): Use bit size. gdb/testsuite/ChangeLog 2020-11-04 Tom Tromey * gdb.ada/array_of_variant.exp: New file. * gdb.ada/array_of_variant/p.adb: New file. * gdb.ada/array_of_variant/pck.ads: New file. * gdb.ada/array_of_variant/pck.adb: New file. --- gdb/ada-lang.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gdb/ada-lang.c') diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7613e19..fe3ea70 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2828,9 +2828,11 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type, base_low_pos = base_low; } - base = value_as_address (array_ptr) - + ((low_pos - base_low_pos) - * TYPE_LENGTH (TYPE_TARGET_TYPE (type0))); + ULONGEST stride = TYPE_FIELD_BITSIZE (slice_type, 0) / 8; + if (stride == 0) + stride = TYPE_LENGTH (TYPE_TARGET_TYPE (type0)); + + base = value_as_address (array_ptr) + (low_pos - base_low_pos) * stride; return value_at_lazy (slice_type, base); } -- cgit v1.1