diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2018-07-25 17:33:08 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2018-08-09 17:17:35 +0100 |
commit | 5ff2bbae198cbd615885f26aa7d065b8cec8c278 (patch) | |
tree | 297f0a5f275af87c325951d2ad818e8ba8d1e05b /gdb/valarith.c | |
parent | e5bbcd0f04911d671d0c43d57df9886c06018705 (diff) | |
download | gdb-5ff2bbae198cbd615885f26aa7d065b8cec8c278.zip gdb-5ff2bbae198cbd615885f26aa7d065b8cec8c278.tar.gz gdb-5ff2bbae198cbd615885f26aa7d065b8cec8c278.tar.bz2 |
gdb: Check element of optimised out vla exists
If a vla is not in memory, and the upper bound is not defined, then we
can't know that an array element exists or not, and we should not try
to access the array element. One case where this happens is for
arrays that have been optimised out, the array will then have
VALUE_LVAL of not_lval, and an undefined upper bound, if we then try
to access an element of this array we will index into random GDB
memory.
An argument could be made that even for arrays that are in inferior
memory, if the upper bound is not defined then we should not try to
access the array element, however, in some of the Fortran tests, it
seems as though we do rely indexing from a base address into an array
which has no bounds defined. In this case GDBs standard protection
for detecting unreadable target memory prevents bad thing happening.
gdb/ChangeLog:
* valarith.c (value_subscripted_rvalue): If an array is not in
memory, and we don't know the upper bound, then we can't know that
the requested element exists or not.
gdb/testsuite/ChangeLog:
* gdb.base/vla-optimized-out.exp: Add new test.
Diffstat (limited to 'gdb/valarith.c')
-rw-r--r-- | gdb/valarith.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gdb/valarith.c b/gdb/valarith.c index 01ca50d..807cdd5 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -189,8 +189,11 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound) ULONGEST elt_size = type_length_units (elt_type); ULONGEST elt_offs = elt_size * (index - lowerbound); - if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type) - && elt_offs >= type_length_units (array_type))) + if (index < lowerbound + || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type) + && elt_offs >= type_length_units (array_type)) + || (VALUE_LVAL (array) != lval_memory + && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type))) { if (type_not_associated (array_type)) error (_("no such vector element (vector not associated)")); |