]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/fortran: fix fetching assumed rank array content
authorAndrew Burgess <aburgess@redhat.com>
Thu, 7 Apr 2022 13:46:18 +0000 (14:46 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 7 Apr 2022 20:12:13 +0000 (21:12 +0100)
commit3fb842cea15503ed101c2d5adb77068206d3d684
tree1c8fe5ae99f2e80bcd37a3b70d219a8be40f7d3c
parent9be5d742dbe3d23f740bbeb5bd1337da8ece536e
gdb/fortran: fix fetching assumed rank array content

Commit:

  commit df7a7bdd9766adebc6b117c31bc617d81c1efd43
  Date:   Thu Mar 17 18:56:23 2022 +0000

      gdb: add support for Fortran's ASSUMED RANK arrays

Added support for Fortran assumed rank arrays.  Unfortunately, this
commit contained a bug that means though GDB can correctly calculate
the rank of an assumed rank array, GDB can't fetch the contents of an
assumed rank array.

The history of this patch can be seen on the mailing list here:

  https://sourceware.org/pipermail/gdb-patches/2022-January/185306.html

The patches that were finally committed can be found here:

  https://sourceware.org/pipermail/gdb-patches/2022-March/186906.html

The original patches did support fetching the array contents, it was
only the later series that introduced the regression.

The problem is that when calculating the array rank the result is a
count of the number of ranks, i.e. this is a 1 based result, 1, 2, 3,
etc.

In contrast, when computing the details of any particular rank the
value passed to the DWARF expression evaluator should be a 0 based
rank offset, i.e. a 0 based number, 0, 1, 2, etc.

In the patches that were originally merged, this was not the case, and
we were passing the 1 based rank number to the expression evaluator,
e.g. passing 1 when we should pass 0, 2 when we should pass 1, etc.
As a result the DWARF expression evaluator was reading the
wrong (undefined) memory, and returning garbage results.

In this commit I have extended the test case to cover checking the
array contents, I've then ensured we make use of the correct rank
value, and extended some comments, and added or adjusted some asserts
as appropriate.
gdb/gdbtypes.c
gdb/testsuite/gdb.fortran/assumedrank.exp
gdb/testsuite/gdb.fortran/assumedrank.f90