This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: fix PR gdb/1158
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Sat, 26 Jul 2008 18:57:33 -0600
- Subject: RFA: fix PR gdb/1158
- Reply-to: Tom Tromey <tromey at redhat dot com>
PR gdb/1158 concerns calling a function via a function pointer that
appears in a struct:
struct struct_with_fnptr
{
int (*func) PARAMS((int));
} function_struct;
(gdb) p function_struct.func(5)
Currently, gdb treats this as a method call, and erroneously adds a
'this' pointer to the call. This yields the wrong result.
This patch fixes the problem by noticing when the right-hand-side of
the member operation is an ordinary data field, and then treating this
as if it were a static member function. I checked all callers to
value_struct_elt, and I think this is the correct thing to do in all
cases.
Regression test included. Built and tested on x86 F8. Ok?
Tom
ChangeLog:
2008-07-26 Tom Tromey <tromey@redhat.com>
PR gdb/1158:
* valops.c (value_struct_elt): Treat function-valued field as a
static method.
testsuite/ChangeLog:
2008-07-26 Tom Tromey <tromey@redhat.com>
* gdb.base/callfuncs.c (struct struct_with_fnptr): New struct.
(function_struct, function_struct_ptr): New globals.
* gdb.base/callfuncs.exp (do_function_calls): Test calling via a
function pointer in a struct.
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.192
diff -u -r1.192 valops.c
--- valops.c 15 Jul 2008 22:13:42 -0000 1.192
+++ valops.c 27 Jul 2008 00:52:21 -0000
@@ -1819,6 +1819,10 @@
back. If it's not callable (i.e., a pointer to function),
gdb should give an error. */
v = search_struct_field (name, *argp, 0, t, 0);
+ /* If we found an ordinary field, then it is not a method call.
+ So, treat it as if it were a static member function. */
+ if (v && static_memfuncp)
+ *static_memfuncp = 1;
}
if (!v)
Index: testsuite/gdb.base/callfuncs.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/callfuncs.c,v
retrieving revision 1.11
diff -u -r1.11 callfuncs.c
--- testsuite/gdb.base/callfuncs.c 6 Feb 2008 03:54:12 -0000 1.11
+++ testsuite/gdb.base/callfuncs.c 27 Jul 2008 00:52:22 -0000
@@ -490,6 +490,14 @@
return ((*func_arg1)(a, b));
}
+struct struct_with_fnptr
+{
+ int (*func) PARAMS((int));
+};
+
+struct struct_with_fnptr function_struct = { doubleit };
+
+struct struct_with_fnptr *function_struct_ptr = &function_struct;
/* Gotta have a main to be able to generate a linked, runnable
executable, and also provide a useful place to set a breakpoint. */
Index: testsuite/gdb.base/callfuncs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/callfuncs.exp,v
retrieving revision 1.24
diff -u -r1.24 callfuncs.exp
--- testsuite/gdb.base/callfuncs.exp 6 Feb 2008 03:54:12 -0000 1.24
+++ testsuite/gdb.base/callfuncs.exp 27 Jul 2008 00:52:22 -0000
@@ -190,6 +190,9 @@
gdb_test "p t_func_values(func_val2,func_val1)" " = 0"
gdb_test "p t_func_values(func_val1,func_val2)" " = 1"
+ gdb_test "p function_struct.func(5)" " = 10"
+ gdb_test "p function_struct_ptr->func(10)" " = 20"
+
# GDB currently screws up the passing of function parameters for
# ABIs that use function descriptors. Instead of passing the
# address of te function descriptor, GDB passes the address of the