I'm trying to intercept a function with Valgrind, according to their example.
I am able to do the interception of glo开发者_运维技巧bal function when building with gcc, however when I compile the same code with g++, interception doesn't work.
Is there anything special in the compiler flags I should specify?
Here's my sample app:
#include <stdio.h>
#include "valgrind.h"
__attribute__ ((noinline))
void foo()
{
printf("inside foo\n");
}
void I_WRAP_SONAME_FNNAME_ZU(NONE,foo)()
{
OrigFn fn;
VALGRIND_GET_ORIG_FN(fn);
printf("*** Before foo()\n");
CALL_FN_v_v(fn);
printf("*** After foo()\n");
}
int main()
{
foo();
return 0;
}
When compiled with GCC, the output is:
*** Before foo()
inside foo
*** After foo()
However when compiled with g++, the output is simply
inside foo
G++ does a name mangling for function without extern "C"
. So you should to find a mangled name (e.g. with nm object
) and use it in your valgrind code. Or you can rewrite your target program to use an extern "C"
function.
精彩评论