diff options
author | Pierre-Marie de Rodat <derodat@adacore.com> | 2015-09-01 16:18:40 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2015-09-23 22:14:18 +0200 |
commit | e6c2c623f7736175e52fce2b61aab60c60eccdf5 (patch) | |
tree | 96702023fcb262163ec07db66506e92c3a8030a3 /gdb/ada-lang.c | |
parent | b6518b3871859f9eeb7653bf2f3baaa43fa0a5d0 (diff) | |
download | gdb-e6c2c623f7736175e52fce2b61aab60c60eccdf5.zip gdb-e6c2c623f7736175e52fce2b61aab60c60eccdf5.tar.gz gdb-e6c2c623f7736175e52fce2b61aab60c60eccdf5.tar.bz2 |
[Ada] Fix handling of array renamings
Compilers can materialize renamings of arrays (or of accesses to arrays)
in Ada into variables whose types are references to the actual array
types. Before this change, trying to use such an array renaming yielded
an error in GDB:
(gdb) print my_array(1)
cannot subscript or call a record
(gdb) print my_array_ptr(1)
cannot subscript or call something of type `(null)'
This behavior comes from bad handling for array renamings, in particular
the OP_FUNCALL expression operator handling from ada-lang.c
(ada_evaluate_subexp): in one place we turn the reference into a
pointer, but the code that follows expect the value to be an array.
This patch fixes how we handle references in call/subscript evaluation
so that we turn these references into the actual array values instead of
pointers to them.
gdb/ChangeLog:
* ada-lang.c (ada_evaluate_subexp) <OP_FUNCALL>: When the input
value is a reference, actually dereference it in order to get
the underlying value.
gdb/testsuite/ChangeLog:
* gdb.ada/array_ptr_renaming.exp: New testcase.
* gdb.ada/array_ptr_renaming/foo.adb: New file.
* gdb.ada/array_ptr_renaming/pack.ads: New file.
Tested on x86_64-linux, no regression.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r-- | gdb/ada-lang.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 6ec2e9d..8089a32 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10642,10 +10642,17 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, therefore already coerced to a simple array. Nothing further to do. */ ; - else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF - || (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY - && VALUE_LVAL (argvec[0]) == lval_memory)) - argvec[0] = value_addr (argvec[0]); + else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_REF) + { + /* Make sure we dereference references so that all the code below + feels like it's really handling the referenced value. Wrapping + types (for alignment) may be there, so make sure we strip them as + well. */ + argvec[0] = ada_to_fixed_value (coerce_ref (argvec[0])); + } + else if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_ARRAY + && VALUE_LVAL (argvec[0]) == lval_memory) + argvec[0] = value_addr (argvec[0]); type = ada_check_typedef (value_type (argvec[0])); |