方案1
在代码中加上这几行:
void __cyg_profile_func_enter( void *func_address, void *call_site )
__attribute__ ((no_instrument_function));
void __cyg_profile_func_exit ( void *func_address, void *call_site )
__attribute__ ((no_instrument_function));
void __cyg_profile_func_enter (void *this_fn, void *call_site) {
printf( "entering %p\n", (int *)this_fn );
}
void __cyg_profile_func_exit (void *this_fn, void *call_site) {
printf( "leaving %p\n", (int *)this_fn );
}
再重新编译执行即可。(gcc -Wall test.c -o test -finstrument-functions;./test)
方案2
将以下代码放在单独文件,如instrument.c:
#include <stdio.h>
void __cyg_profile_func_enter (void *this_fn, void *call_site) {
printf( "entering %p\n", this_fn );
}
void __cyg_profile_func_exit (void *this_fn, void *call_site) {
printf( "leaving %p\n", this_fn );
}
然后gcc -c instrument.c -o instrument.o;gcc -finstrument-functions test.c profile.o -o test;./test