aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-valprint.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-10-24 11:12:11 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-12-01 22:31:30 +0000
commit5bbd8269fa8d138e8ea1dd3c8cdf42412c1dfa41 (patch)
tree424045e6cff4208f62566e5ab727aafe23cfca7c /gdb/f-valprint.c
parent82e3b5645f9c4edc1d84e57c32665d0e76bbbd77 (diff)
downloadgdb-5bbd8269fa8d138e8ea1dd3c8cdf42412c1dfa41.zip
gdb-5bbd8269fa8d138e8ea1dd3c8cdf42412c1dfa41.tar.gz
gdb-5bbd8269fa8d138e8ea1dd3c8cdf42412c1dfa41.tar.bz2
gdb/fortran: array stride support
Currently GDB supports a byte or bit stride on arrays, in DWARF this would be DW_AT_bit_stride or DW_AT_byte_stride on DW_TAG_array_type. However, DWARF can also support DW_AT_byte_stride or DW_AT_bit_stride on DW_TAG_subrange_type, the tag used to describe each dimension of an array. Strides on subranges are used by gFortran to represent Fortran arrays, and this commit adds support for this to GDB. I've extended the range_bounds struct to include the stride information. The name is possibly a little inaccurate now, but this still sort of makes sense, the structure represents information about the bounds of the range, and also how to move from the lower to the upper bound (the stride). I've added initial support for bit strides, but I've never actually seen an example of this being generated. Further, I don't really see right now how GDB would currently handle a bit stride that was not a multiple of the byte size as the code in, for example, valarith.c:value_subscripted_rvalue seems geared around byte addressing. As a consequence if we see a bit stride that is not a multiple of 8 then GDB will give an error. gdb/ChangeLog: * dwarf2read.c (read_subrange_type): Read bit and byte stride and create a range with stride where appropriate. * f-valprint.c: Include 'gdbarch.h'. (f77_print_array_1): Take the stride into account when walking the array. Also convert the stride into addressable units. * gdbtypes.c (create_range_type): Initialise the stride to constant zero. (create_range_type_with_stride): New function, initialise the range as normal, and then setup the stride. (has_static_range): Include the stride here. Also change the return type to bool. (create_array_type_with_stride): Consider the range stride if the array isn't given its own stride. (resolve_dynamic_range): Resolve the stride if needed. * gdbtypes.h (struct range_bounds) <stride>: New member variable. (struct range_bounds) <flag_is_byte_stride>: New member variable. (TYPE_BIT_STRIDE): Define. (TYPE_ARRAY_BIT_STRIDE): Define. (create_range_type_with_stride): Declare. * valarith.c (value_subscripted_rvalue): Take range stride into account when walking the array. gdb/testsuite/ChangeLog: * gdb.fortran/derived-type-striding.exp: New file. * gdb.fortran/derived-type-striding.f90: New file. * gdb.fortran/array-slices.exp: New file. * gdb.fortran/array-slices.f90: New file. Change-Id: I9af2bcd1f2d4c56f76f5f3f9f89d8f06bef10d9a
Diffstat (limited to 'gdb/f-valprint.c')
-rw-r--r--gdb/f-valprint.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index d5515c8..35dc90d 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -34,6 +34,7 @@
#include "block.h"
#include "dictionary.h"
#include "cli/cli-style.h"
+#include "gdbarch.h"
static void f77_get_dynamic_length_of_aggregate (struct type *);
@@ -120,7 +121,12 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
if (nss != ndimensions)
{
- size_t dim_size = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
+ struct gdbarch *gdbarch = get_type_arch (type);
+ size_t dim_size = type_length_units (TYPE_TARGET_TYPE (type));
+ int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
+ size_t byte_stride = TYPE_ARRAY_BIT_STRIDE (type) / (unit_size * 8);
+ if (byte_stride == 0)
+ byte_stride = dim_size;
size_t offs = 0;
for (i = lowerbound;
@@ -137,7 +143,7 @@ f77_print_array_1 (int nss, int ndimensions, struct type *type,
value_embedded_offset (subarray),
value_address (subarray),
stream, recurse, subarray, options, elts);
- offs += dim_size;
+ offs += byte_stride;
fprintf_filtered (stream, ") ");
}
if (*elts >= options->print_max && i < upperbound)