* RFA: fix PR gdb/1158
@ 2008-07-27 0:57 Tom Tromey
2008-07-27 1:36 ` Daniel Jacobowitz
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2008-07-27 0:57 UTC (permalink / raw)
To: gdb-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: RFA: fix PR gdb/1158
2008-07-27 0:57 RFA: fix PR gdb/1158 Tom Tromey
@ 2008-07-27 1:36 ` Daniel Jacobowitz
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2008-07-27 1:36 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On Sat, Jul 26, 2008 at 06:57:33PM -0600, Tom Tromey wrote:
> Regression test included. Built and tested on x86 F8. Ok?
This is OK, thanks.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-07-27 1:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-27 0:57 RFA: fix PR gdb/1158 Tom Tromey
2008-07-27 1:36 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox