From ccdc02ed07bbed9468c275a943fc5a970e949e99 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 9 Mar 2021 07:36:26 -0700 Subject: [PATCH] Fix function call regression in new evaluator The internal AdaCore test suite revealed a bug in the new evaluator. A hunk of evaluate_funcall was not correctly transcribed. This was not caught in my original testing because the feature in question was apparently not tested in gdb. This patch fixes the oversight. The idea here is that ordinary function calls should use the function's formal parameter types as the expected types of subexpressions. Regression tested on x86-64 Fedora 32. gdb/ChangeLog 2021-03-09 Tom Tromey * eval.c (operation::evaluate_funcall): Use function formal parameter types when evaluating. gdb/testsuite/ChangeLog 2021-03-09 Tom Tromey * gdb.base/cast-call.exp: New file. * gdb.base/cast-call.c: New file. --- gdb/ChangeLog | 5 ++++ gdb/eval.c | 10 +++++++- gdb/testsuite/ChangeLog | 5 ++++ gdb/testsuite/gdb.base/cast-call.c | 37 +++++++++++++++++++++++++++ gdb/testsuite/gdb.base/cast-call.exp | 38 ++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/cast-call.c create mode 100644 gdb/testsuite/gdb.base/cast-call.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 80f541551fa..97fcd5e579e 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 5af728a9bbd..530ff152134 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 d3e91f611a9..4ea506cc9df 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 00000000000..bceae1b6ab7 --- /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 00000000000..96f84f107fc --- /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" -- 2.30.2