diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 80f541551f..97fcd5e579 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-09 Tom Tromey + + * eval.c (operation::evaluate_funcall): Use function formal + parameter types when evaluating. + 2021-03-09 Andrew Burgess * gdb-gdb.py.in (StructMainTypePrettyPrinter) : diff --git a/gdb/eval.c b/gdb/eval.c index 5af728a9bb..530ff15213 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -687,8 +687,16 @@ operation::evaluate_funcall (struct type *expect_type, std::vector vals (args.size ()); value *callee = evaluate_with_coercion (exp, noside); + struct type *type = value_type (callee); + if (type->code () == TYPE_CODE_PTR) + type = TYPE_TARGET_TYPE (type); for (int i = 0; i < args.size (); ++i) - vals[i] = args[i]->evaluate_with_coercion (exp, noside); + { + if (i < type->num_fields ()) + vals[i] = args[i]->evaluate (type->field (i).type (), exp, noside); + else + vals[i] = args[i]->evaluate_with_coercion (exp, noside); + } return evaluate_subexp_do_call (exp, noside, callee, vals, function_name, expect_type); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d3e91f611a..4ea506cc9d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2021-03-09 Tom Tromey + + * gdb.base/cast-call.exp: New file. + * gdb.base/cast-call.c: New file. + 2021-03-09 Andrew Burgess * gdb.gdb/python-helper.exp: New file. diff --git a/gdb/testsuite/gdb.base/cast-call.c b/gdb/testsuite/gdb.base/cast-call.c new file mode 100644 index 0000000000..bceae1b6ab --- /dev/null +++ b/gdb/testsuite/gdb.base/cast-call.c @@ -0,0 +1,37 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +struct thestruct +{ + int x; +}; + +int +f (struct thestruct value) +{ + return value.x; +} + +int +main () +{ + struct thestruct y; + y.x = 0; + + int result = f (y); /* STOP */ + return 0; +} diff --git a/gdb/testsuite/gdb.base/cast-call.exp b/gdb/testsuite/gdb.base/cast-call.exp new file mode 100644 index 0000000000..96f84f107f --- /dev/null +++ b/gdb/testsuite/gdb.base/cast-call.exp @@ -0,0 +1,38 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +if {[target_info exists gdb,cannot_call_functions]} { + unsupported "this target can not call functions" + continue +} + +standard_testfile .c + +if { [prepare_for_testing "failed to prepare" ${testfile} $srcfile] } { + return -1 +} + +if {![runto_main]} { + untested "could not run to main" + return -1 +} + +gdb_breakpoint [gdb_get_line_number "STOP"] +gdb_continue_to_breakpoint "STOP" + +gdb_test "print f({73})" " = 73" "call f with braced argument"