aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-lang.c
diff options
context:
space:
mode:
authorRichard Bunt <richard.bunt@arm.com>2019-03-06 08:23:00 +0000
committerRichard Bunt <richard.bunt@arm.com>2019-03-06 08:24:12 +0000
commitaa3cfbda2f2af71044949b5692ce51cafb023d13 (patch)
tree1cba99e017e03ebdd44207d76fb7d23f0e179fcd /gdb/f-lang.c
parent2d0d5fc6f085dedd7988b29e58fdc4dc2081472e (diff)
downloadgdb-aa3cfbda2f2af71044949b5692ce51cafb023d13.zip
gdb-aa3cfbda2f2af71044949b5692ce51cafb023d13.tar.gz
gdb-aa3cfbda2f2af71044949b5692ce51cafb023d13.tar.bz2
Fortran function calls with arguments
Prior to this patch, calling functions on the inferior with arguments and then using these arguments within a function resulted in an invalid memory access. This is because Fortran arguments are typically passed as pointers to values. It is possible to call Fortran functions, but memory must be allocated in the inferior, so a pointer can be passed to the function, and the language must be set to C to enable C-style casting. This is cumbersome and not a pleasant debug experience. This patch implements the GNU Fortran argument passing conventions with caveats. Firstly, it does not handle the VALUE attribute as there is insufficient DWARF information to determine when this is the case. Secondly, functions with optional parameters can only be called with all parameters present. Both these cases are marked as KFAILS in the test. Since the GNU Fortran argument passing convention has been implemented, there is no guarantee that this patch will work correctly, in all cases, with other compilers. Despite these limitations, this patch improves the ease with which functions can be called in many cases, without taking away the existing approach of calling with the language set to C. Regression tested on x86_64, aarch64 and POWER9 with GCC 7.3.0. Regression tested with Ada on x86_64. Regression tested with native-extended-gdbserver target board. gdb/ChangeLog: * eval.c (evaluate_subexp_standard): Call Fortran argument wrapping logic. * f-lang.c (struct value): A value which can be passed into a Fortran function call. (fortran_argument_convert): Wrap Fortran arguments in a pointer where appropriate. (struct type): Value ready for a Fortran function call. (fortran_preserve_arg_pointer): Undo check_typedef, the pointer is needed. * f-lang.h (fortran_argument_convert): Declaration. (fortran_preserve_arg_pointer): Declaration. * infcall.c (value_arg_coerce): Call Fortran argument logic. gdb/testsuite/ChangeLog: * gdb.fortran/function-calls.exp: New file. * gdb.fortran/function-calls.f90: New test.
Diffstat (limited to 'gdb/f-lang.c')
-rw-r--r--gdb/f-lang.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 4ff828b..6eb9b23 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -27,6 +27,7 @@
#include "parser-defs.h"
#include "language.h"
#include "varobj.h"
+#include "gdbcore.h"
#include "f-lang.h"
#include "valprint.h"
#include "value.h"
@@ -371,3 +372,40 @@ _initialize_f_language (void)
{
f_type_data = gdbarch_data_register_post_init (build_fortran_types);
}
+
+/* See f-lang.h. */
+
+struct value *
+fortran_argument_convert (struct value *value, bool is_artificial)
+{
+ if (!is_artificial)
+ {
+ /* If the value is not in the inferior e.g. registers values,
+ convenience variables and user input. */
+ if (VALUE_LVAL (value) != lval_memory)
+ {
+ struct type *type = value_type (value);
+ const int length = TYPE_LENGTH (type);
+ const CORE_ADDR addr
+ = value_as_long (value_allocate_space_in_inferior (length));
+ write_memory (addr, value_contents (value), length);
+ struct value *val
+ = value_from_contents_and_address (type, value_contents (value),
+ addr);
+ return value_addr (val);
+ }
+ else
+ return value_addr (value); /* Program variables, e.g. arrays. */
+ }
+ return value;
+}
+
+/* See f-lang.h. */
+
+struct type *
+fortran_preserve_arg_pointer (struct value *arg, struct type *type)
+{
+ if (TYPE_CODE (value_type (arg)) == TYPE_CODE_PTR)
+ return value_type (arg);
+ return type;
+}