========
#include <stdio.h>
#include <execinfo.h>
static int level = 1;
void __attribute__((__no_instrument_function__))
__cyg_profile_func_enter(void *this_func, void *call_site)
{
printf("pushd %d: \n", level++);
backtrace_symbols_fd(&this_func, 1, 1);
}
void __attribute__((__no_instrument_function__))
__cyg_profile_func_exit(void *this_func, void *call_site)
{
printf("popd %d: \n", --level);
backtrace_symbols_fd(&this_func, 1, 1);
}
////////////////////////////////////////////////
void xputs(char *s)
{
puts(s);
}
main()
{
xputs("Hello World!");
return 0;
}
zjw@ubuntu:~/zzz/include$ gcc a.c -rdynamic -finstrument-functions
zjw@ubuntu:~/zzz/include$ ./a.out
pushd 1:
./a.out(main+0x0)[0x80487a7]
pushd 2:
./a.out(xputs+0x0)[0x804876e]
Hello World!
popd 2:
./a.out(xputs+0x0)[0x804876e]
popd 1:
./a.out(main+0x0)[0x80487a7]
参考 http://blog.youkuaiyun.com/wind19/article/details/6105617
=========