1、gcc参数-finstrument-functions,__cyg_profile_func_enter 函数和__cyg_profile_func_exit 函数的使用:
//#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//#define __USE_GNU
#include <dlfcn.h>
__attribute__((no_instrument_function))
void
__cyg_profile_func_enter (void *this_fn, void *call_site)
{
printf("%s,%p,called by %p\n",__func__,this_fn,call_site);
}
__attribute__((no_instrument_function))
void
__cyg_profile_func_exit (void *this_fn, void *call_site){
printf("%s,%p,called by %p\n",__func__,this_fn,call_site);
}
void hello1()
{
printf("hello1\n");
}
int main()
{
printf("main\n");
hello1();
return 1;
}
$ gcc -finstrument-functions -o main main.c
$./main
__cyg_profile_func_enter,0x400642,called by 0x