aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/eval.c15
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.cp/method-call-in-c.cc44
-rw-r--r--gdb/testsuite/gdb.cp/method-call-in-c.exp43
-rw-r--r--gdb/valops.c7
6 files changed, 121 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 53b3c31..04ea77f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ PR gdb/27994
+ * eval.c (structop_base_operation::evaluate_funcall): Add a
+ nullptr to the end of the args array, which should not be included
+ in the argument array_view. Pass all the arguments through to
+ value_struct_elt.
+ * valops.c (search_struct_method): Update header comment.
+ (value_struct_elt): Likewise.
+
2021-06-25 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (create_addrmap_from_aranges): Change padding
diff --git a/gdb/eval.c b/gdb/eval.c
index 659493c..ab070a3 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -872,7 +872,9 @@ structop_base_operation::evaluate_funcall
(struct type *expect_type, struct expression *exp, enum noside noside,
const std::vector<operation_up> &args)
{
- std::vector<value *> vals (args.size () + 1);
+ /* Allocate space for the function call arguments. Include space for a
+ `this' pointer at the start, and a trailing nullptr. */
+ std::vector<value *> vals (args.size () + 2);
/* First, evaluate the structure into vals[0]. */
enum exp_opcode op = opcode ();
if (op == STRUCTOP_STRUCT)
@@ -918,9 +920,16 @@ structop_base_operation::evaluate_funcall
}
}
+ /* Evaluate the arguments, and add the trailing nullptr. The '+ 1' here
+ is to allow for the `this' pointer we placed into vals[0]. */
for (int i = 0; i < args.size (); ++i)
vals[i + 1] = args[i]->evaluate_with_coercion (exp, noside);
- gdb::array_view<value *> arg_view = vals;
+ vals[args.size () + 1] = nullptr;
+
+ /* The array view includes the `this' pointer, but not the trailing
+ nullptr. */
+ gdb::array_view<value *> arg_view
+ = gdb::make_array_view (&vals[0], args.size () + 1);
int static_memfuncp;
value *callee;
@@ -941,7 +950,7 @@ structop_base_operation::evaluate_funcall
{
struct value *temp = vals[0];
- callee = value_struct_elt (&temp, &vals[1], tstr,
+ callee = value_struct_elt (&temp, &vals[0], tstr,
&static_memfuncp,
op == STRUCTOP_STRUCT
? "structure" : "structure pointer");
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index fa54765..878921d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2021-06-25 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ PR gdb/27994
+ * gdb.cp/method-call-in-c.cc: New file.
+ * gdb.cp/method-call-in-c.exp: New file.
+
2021-06-25 Tom Tromey <tom@tromey.com>
* lib/gdb.exp (add_gdb_index, ensure_gdb_index): Add "style"
diff --git a/gdb/testsuite/gdb.cp/method-call-in-c.cc b/gdb/testsuite/gdb.cp/method-call-in-c.cc
new file mode 100644
index 0000000..09e4285
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/method-call-in-c.cc
@@ -0,0 +1,44 @@
+/* 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 baz_type
+{
+ int a = 0;
+ int b = 1;
+ int c = 2;
+};
+
+struct foo_type
+{
+ int func (baz_type b, float f)
+ {
+ return var++;
+ }
+
+ int var = 123;
+};
+
+int
+main (void)
+{
+ baz_type b = {};
+ float f = 1.0;
+
+ foo_type foo;
+
+ return foo.func (b, f); /* Break here. */
+}
diff --git a/gdb/testsuite/gdb.cp/method-call-in-c.exp b/gdb/testsuite/gdb.cp/method-call-in-c.exp
new file mode 100644
index 0000000..0e6851b
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/method-call-in-c.exp
@@ -0,0 +1,43 @@
+# 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/>.
+
+# Ensure that calling a member function works correctly even when the
+# language is forced to 'C' (this should be fine, so long at no
+# overload resolution is required), or when overload-resolution is
+# off.
+
+standard_testfile .cc
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+ return -1
+}
+
+if ![runto_main] then {
+ return 0
+}
+
+gdb_breakpoint [gdb_get_line_number "Break here"]
+gdb_continue_to_breakpoint "Break here"
+
+set result 123
+foreach_with_prefix lang { c++ c } {
+ foreach_with_prefix overload_resolution { on off } {
+ gdb_test_no_output "set overload-resolution ${overload_resolution}"
+ gdb_test "set language ${lang}"
+
+ gdb_test "print foo.func (b, f)" " = ${result}"
+ incr result
+ }
+}
diff --git a/gdb/valops.c b/gdb/valops.c
index 8694c12..2b57930 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -2181,6 +2181,10 @@ search_struct_field (const char *name, struct value *arg1,
ARG1 by OFFSET bytes, and search in it assuming it has (class) type
TYPE.
+ The ARGS array is a list of argument values used to help finding NAME,
+ though ARGS can be nullptr. If ARGS is not nullptr then the list itself
+ must have a NULL at the end.
+
If found, return value, else if name matched and args not return
(value) -1, else return NULL. */
@@ -2309,7 +2313,8 @@ search_struct_method (const char *name, struct value **arg1p,
ERR is used in the error message if *ARGP's type is wrong.
C++: ARGS is a list of argument types to aid in the selection of
- an appropriate method. Also, handle derived types.
+ an appropriate method. Also, handle derived types. The array ARGS must
+ have a NULL at the end.
STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
where the truthvalue of whether the function that was resolved was