[Ada] Fix unconstrained packed array size
When ada-lang transforms an array descriptor type (an XUP structure) into an array type, the size of the array type is computed by using the element size, and multiplying it by the number of elements in that array. This does not work, however, for packed arrays, where the *packed* size in bits needs to be used. This usually does not cause any problem, because we end up reading more memory than needed. However, we have observed on LynxOS a memory error while trying to read the entire array, because the larger-than-needed read tried to read past the end of the stack into inaccessible memory. This patch fixes the problem by correctly computing the array size in bytes in the case of packed arrays. gdb/ChangeLog: * ada-lang.c (ada_type_of_array): Fix the size of the array in the case of an unconstrained packed array. gdb/testsuite/ChangeLog: * gdb.ada/packed_array: Expand testcase to test printing of unconstrained packed array.
This commit is contained in:
parent
93084bcabb
commit
e67ad678a1
7 changed files with 86 additions and 2 deletions
|
@ -1823,8 +1823,25 @@ ada_type_of_array (struct value *arr, int bounds)
|
|||
elt_type = create_array_type (array_type, elt_type, range_type);
|
||||
|
||||
if (ada_is_unconstrained_packed_array_type (value_type (arr)))
|
||||
TYPE_FIELD_BITSIZE (elt_type, 0) =
|
||||
decode_packed_array_bitsize (value_type (arr));
|
||||
{
|
||||
/* We need to store the element packed bitsize, as well as
|
||||
recompute the array size, because it was previously
|
||||
computed based on the unpacked element size. */
|
||||
LONGEST lo = value_as_long (low);
|
||||
LONGEST hi = value_as_long (high);
|
||||
|
||||
TYPE_FIELD_BITSIZE (elt_type, 0) =
|
||||
decode_packed_array_bitsize (value_type (arr));
|
||||
/* If the array has no element, then the size is already
|
||||
zero, and does not need to be recomputed. */
|
||||
if (lo < hi)
|
||||
{
|
||||
int array_bitsize =
|
||||
(hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0);
|
||||
|
||||
TYPE_LENGTH (array_type) = (array_bitsize + 7) / 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lookup_pointer_type (elt_type);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue