gdb/fortran: Support negative array stride in one limited case

This commit adds support for negative Fortran array strides in one
limited case, that is the case of a single element array with a
negative array stride.

The changes in this commit will be required in order for more general
negative array stride support to work correctly, however, right now
other problems in GDB prevent negative array strides from working in
the general case.

The reason negative array strides don't currently work in the general
case is that when dealing with such arrays, the base address for the
objects data is actually the highest addressed element, subsequent
elements are then accessed with a negative offset from that address,
and GDB is not currently happy with this configuration.

The changes here can be summarised as, stop treating signed values as
unsigned, specifically, the array stride, and offsets calculated using
the array stride.

This issue was identified on the mailing list by Sergio:

  https://sourceware.org/ml/gdb-patches/2020-01/msg00360.html

The test for this issue is a new one written by me as the copyright
status of the original test is currently unknown.

gdb/ChangeLog:

	* gdbtypes.c (create_array_type_with_stride): Handle negative
	array strides.
	* valarith.c (value_subscripted_rvalue): Likewise.

gdb/testsuite/ChangeLog:

	* gdb.fortran/derived-type-striding.exp: Add a new test.
	* gdb.fortran/derived-type-striding.f90: Add pointer variable for
	new test.
This commit is contained in:
Andrew Burgess
2020-01-18 22:38:29 +00:00
parent 09624f1fec
commit 9e80cfa14e
6 changed files with 31 additions and 6 deletions

View File

@@ -1223,7 +1223,7 @@ create_array_type_with_stride (struct type *result_type,
&& !type_not_allocated (result_type)))
{
LONGEST low_bound, high_bound;
unsigned int stride;
int stride;
/* If the array itself doesn't provide a stride value then take
whatever stride the range provides. Don't update BIT_STRIDE as
@@ -1241,9 +1241,18 @@ create_array_type_with_stride (struct type *result_type,
In such cases, the array length should be zero. */
if (high_bound < low_bound)
TYPE_LENGTH (result_type) = 0;
else if (stride > 0)
TYPE_LENGTH (result_type) =
(stride * (high_bound - low_bound + 1) + 7) / 8;
else if (stride != 0)
{
/* Ensure that the type length is always positive, even in the
case where (for example in Fortran) we have a negative
stride. It is possible to have a single element array with a
negative stride in Fortran (this doesn't mean anything
special, it's still just a single element array) so do
consider that case when touching this code. */
LONGEST element_count = abs (high_bound - low_bound + 1);
TYPE_LENGTH (result_type)
= ((abs (stride) * element_count) + 7) / 8;
}
else
TYPE_LENGTH (result_type) =
TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);