aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-03-09 07:36:26 -0700
committerTom Tromey <tromey@adacore.com>2021-03-09 07:36:26 -0700
commitccdc02ed07bbed9468c275a943fc5a970e949e99 (patch)
treeda564e8abf704100761bc9f9bb28145dd51df327 /gdb
parent5dc75cf3254c1b3c5b62125f47b543407836a4b6 (diff)
downloadgdb-ccdc02ed07bbed9468c275a943fc5a970e949e99.zip
gdb-ccdc02ed07bbed9468c275a943fc5a970e949e99.tar.gz
gdb-ccdc02ed07bbed9468c275a943fc5a970e949e99.tar.bz2
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 <tromey@adacore.com> * eval.c (operation::evaluate_funcall): Use function formal parameter types when evaluating. gdb/testsuite/ChangeLog 2021-03-09 Tom Tromey <tromey@adacore.com> * gdb.base/cast-call.exp: New file. * gdb.base/cast-call.c: New file.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/eval.c10
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/cast-call.c37
-rw-r--r--gdb/testsuite/gdb.base/cast-call.exp38
5 files changed, 94 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 80f5415..97fcd5e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-09 Tom Tromey <tromey@adacore.com>
+
+ * eval.c (operation::evaluate_funcall): Use function formal
+ parameter types when evaluating.
+
2021-03-09 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb-gdb.py.in (StructMainTypePrettyPrinter) <owner_to_string>:
diff --git a/gdb/eval.c b/gdb/eval.c
index 5af728a..530ff15 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -687,8 +687,16 @@ operation::evaluate_funcall (struct type *expect_type,
std::vector<value *> 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 d3e91f6..4ea506c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-09 Tom Tromey <tromey@adacore.com>
+
+ * gdb.base/cast-call.exp: New file.
+ * gdb.base/cast-call.c: New file.
+
2021-03-09 Andrew Burgess <andrew.burgess@embecosm.com>
* 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 0000000..bceae1b
--- /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 <http://www.gnu.org/licenses/>. */
+
+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 0000000..96f84f1
--- /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 <http://www.gnu.org/licenses/>.
+
+
+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"