[PATCH 0/8] Fortran Array Slicing and Striding Support

Andrew Burgess
2020-08-13T12:58:52Z

This series adds support to GDB's CLI for taking slices (including
with strides) from a Fortrn array, so after this series, things like
this will work:

(gdb) p array (8:3:-2,2:9:3)
$2 = ((18, 16, 14) (48, 46, 44) (78, 76, 74))

There have been a couple of attempts to provide Fortran array
slice/stride support in the past that I'm aware of:

https://sourceware.org/pipermail/gdb-patches/2017-September/143121.html
https://sourceware.org/pipermail/gdb-patches/2016-February/131539.html

I know that some variation of these patches are currently used in
Fedora's GDB[1] and the GDB installed on my Fedora machine can pass
most of the tests I've added here.

However, having looked at the past implementations that were posted to
the list, the approach I'm taking here is a little different.

The previous approaches took the approach of walking each dimension of
the array, at each dimension extracting a slighlt smaller slice.
Though this approach is fine, it does have one problem related to
memory usage and large arrays. If the original array is large, and
extracting the slice for the first dimension would exceed the
max-value-size, then GDB would be unable to load the slice, even if
the final value would have been under the max-value-size.

The patches presented here have the following features:

- The type of the array slice, including upper and lower bounds,
correctly match the behaviour within Fortran.

- Extracting small slices from very large arrays will not exceed the
max-value-size.

- The extracted slice is (by default) an in-memory lvalue, which
aliases onto the original array and can be assigned to, and have
addresses of elements taken and the results will be correct.

- A Fortran compiler will sometimes repack arrays to make the slice
data contiguous, GDB can do this too when it is essential, and can
optionally do this in all cases if the user requires.

- Repacking is again done with an eye to memory usage, so repacking a
small slice from a large array will not exceed the max-value-size.

I don't propose that these patches, or at least the later patches in
this series, be merged before the GDB 10 branching, but I would be
interested in any feedback.

Thanks,
Andrew

[1] https://sourceware.org/pipermail/gdb-patches/2016-April/132383.html

---

Andrew Burgess (8):
gdbsupport: Provide global operators |=, &=, and ^= for enum bit flags
gdbsupport: Make function arguments constant in enum-flags.h
gdb/fortran: Clean up array/string expression evaluation
gdb/fortran: Move Fortran expression handling into f-lang.c
gdb/fortran: Change whitespace when printing arrays
gdb: Convert enum range_type to a bit field enum
gdb/testsuite: Add missing expected results
gdb/fortran: Add support for Fortran array slices at the GDB prompt

gdb/ChangeLog | 102 +++
gdb/Makefile.in | 1 +
gdb/NEWS | 13 +
gdb/doc/ChangeLog | 7 +
gdb/doc/gdb.texinfo | 30 +
gdb/eval.c | 225 +----
gdb/expprint.c | 114 ++-
gdb/expression.h | 39 +-
gdb/f-array-walker.h | 255 ++++++
gdb/f-exp.y | 52 +-
gdb/f-lang.c | 779 ++++++++++++++++++
gdb/f-lang.h | 19 +-
gdb/f-valprint.c | 187 +++--
gdb/fortran-operator.def | 8 +
gdb/gdbtypes.c | 12 +-
gdb/parse.c | 25 +-
gdb/parser-defs.h | 16 +
gdb/rust-exp.y | 21 +-
gdb/rust-lang.c | 25 +-
gdb/std-operator.def | 8 -
gdb/testsuite/ChangeLog | 22 +
.../gdb.fortran/array-slices-bad.exp | 69 ++
.../gdb.fortran/array-slices-bad.f90 | 42 +
.../gdb.fortran/array-slices-sub-slices.exp | 111 +++
.../gdb.fortran/array-slices-sub-slices.f90 | 96 +++
gdb/testsuite/gdb.fortran/array-slices.exp | 264 +++++-
gdb/testsuite/gdb.fortran/array-slices.f90 | 364 +++++++-
.../gdb.fortran/class-allocatable-array.exp | 2 +-
gdb/testsuite/gdb.fortran/multi-dim.exp | 2 +-
gdb/testsuite/gdb.fortran/vla-sizeof.exp | 4 +-
gdb/testsuite/gdb.fortran/vla-type.exp | 6 +-
gdb/testsuite/gdb.mi/mi-vla-fortran.exp | 2 +-
gdbsupport/ChangeLog | 22 +
gdbsupport/enum-flags.h | 50 +-
34 files changed, 2485 insertions(+), 509 deletions(-)
create mode 100644 gdb/f-array-walker.h
create mode 100644 gdb/testsuite/gdb.fortran/array-slices-bad.exp
create mode 100644 gdb/testsuite/gdb.fortran/array-slices-bad.f90
create mode 100644 gdb/testsuite/gdb.fortran/array-slices-sub-slices.exp
create mode 100644 gdb/testsuite/gdb.fortran/array-slices-sub-slices.f90

--
2.25.4