gdb/fortran: array stride support
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 24 Oct 2019 10:12:11 +0000 (11:12 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Sun, 1 Dec 2019 22:31:30 +0000 (22:31 +0000)
commit5bbd8269fa8d138e8ea1dd3c8cdf42412c1dfa41
tree424045e6cff4208f62566e5ab727aafe23cfca7c
parent82e3b5645f9c4edc1d84e57c32665d0e76bbbd77
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
gdb/ChangeLog
gdb/dwarf2read.c
gdb/f-valprint.c
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/array-slices.exp [new file with mode: 0644]
gdb/testsuite/gdb.fortran/array-slices.f90 [new file with mode: 0644]
gdb/testsuite/gdb.fortran/derived-type-striding.exp [new file with mode: 0644]
gdb/testsuite/gdb.fortran/derived-type-striding.f90 [new file with mode: 0644]
gdb/valarith.c