|
From: Patrick H. <hec...@in...> - 2010-07-20 15:04:09
|
Hi everybody,
I have a question about function wrapping for C++ code:
I want to wrap a function foo:
int foo( int x, int y )
{
return x + y;
}
with the following wrapper code:
int I_WRAP_SONAME_FNNAME_ZU(NONE,foo)( int x, int y )
{
int result;
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
printf("foo's wrapper: args %d %d\n", x, y);
CALL_FN_W_WW(result, fn, x,y);
printf("foo's wrapper: result %d\n", result);
return result;
}
This works fine with gcc but not with g++.
The reason for that is that the mangled label does not match the wrapper
label:
I compile with -S to assembler:
The mangled name for foo: _Z3fooii
The mangled name for foo wrapper: _Z15_vgwZU_NONE_fooii
When I change the label of the wrapper function by hand in the assembler
file to:
_vgwZU_NONE__Z3fooii Valgrind wraps the function correctly.
It seems that it is not possible to wrap C++ functions because the macros
are not powerful enough!
Is there any other possibility to wrap C++ functions?
My solution:
One possibilty could be to extend the Macros in valgrind.h by integrating a
mangeling mechanism to generate correct wrapper names. Can anybody confirm
this?
Thanks in advance.
Mit freundlichen Grüßen / Kind Regards
*Patrick Heckeler*
University of Tuebingen
Wilhelm-Schickard-Institute
Computer Engineering Department
Sand 13 D-72076 Tuebingen
Office B 204
Phone: +49 (0)7071 29 78 977
Fax: +49 (0)7071 29 50 62
Skype: p_heckeler
Email: heckeler [at] informatik [dot] uni-tuebingen [dot] de
WWW: http://www.ti.uni-tuebingen.de/Patrick-Heckeler.876.0.html
|
|
From: Dan K. <da...@ke...> - 2010-07-20 15:13:42
|
On Tue, Jul 20, 2010 at 7:33 AM, Patrick Heckeler <hec...@in...> wrote: > Is there any other possibility to wrap C++ functions? Well, you could use extern "C" on that one function to disable the mangling, but you already knew that. (And it won't work if you have several functions with the same name but different signatures.) - Dan |
|
From: Patrick H. <hec...@in...> - 2010-07-20 15:43:48
|
I have tested extern "C"and it works. But I want to use the wrapping later on for C++ methods. And extern "C" cannot handle class methods :-) On 20 July 2010 17:13, Dan Kegel <da...@ke...> wrote: > On Tue, Jul 20, 2010 at 7:33 AM, Patrick Heckeler > <hec...@in...> wrote: > > Is there any other possibility to wrap C++ functions? > > Well, you could use extern "C" on that one function to disable the > mangling, > but you already knew that. > (And it won't work if you have several functions with the same name but > different signatures.) > - Dan > |
|
From: Bart V. A. <bva...@ac...> - 2010-07-20 16:53:44
|
On Tue, Jul 20, 2010 at 5:43 PM, Patrick Heckeler < hec...@in...> wrote: > > On 20 July 2010 17:13, Dan Kegel <da...@ke...> wrote: > >> On Tue, Jul 20, 2010 at 7:33 AM, Patrick Heckeler >> <hec...@in...> wrote: >> > Is there any other possibility to wrap C++ functions? >> >> Well, you could use extern "C" on that one function to disable the >> mangling, >> but you already knew that. >> (And it won't work if you have several functions with the same name but >> different signatures.) >> - Dan >> > > I have tested extern "C"and it works. But I want to use the wrapping later > on for C++ methods. And extern "C" cannot handle class methods :-) > It can, at least if you specify the mangled name. There are several examples in drd/drd_qtcore_intercepts.c. Bart. |