程序执行的过程中,不知道这个函数是谁发起的调用,那么可以通过这样的方式将函数的调用路径打印出来。
在函数中增加一下语句
-
void *bt[20];
-
char **strings;
-
size_t sz;
-
-
sz = backtrace(bt, 20);
-
strings = backtrace_symbols(bt, sz);
-
for(i = 0; i < sz; ++i)
-
fprintf(stderr, "%s/n", strings[i]);
在程序链接的时候,加入 -rdynamic参数,将函数的符号表编译到程序里面,否则将只会打印函数的16进制地址。
如下所示一个函数调用的路径,被清楚的打印了
-
./build/exe/Z3GatewayHost() [0x4579ec]
-
./build/exe/Z3GatewayHost(emberAfSendUnicastToBindingsWithCallback+0xcc) [0x45835b]
-
./build/exe/Z3GatewayHost(emberAfSendCommandUnicastToBindingsWithCallback+0x33) [0x45cdf8]
-
./build/exe/Z3GatewayHost() [0x44a271]
-
./build/exe/Z3GatewayHost(emberAfPluginReportingTickEventHandler+0x226) [0x449f7a]
-
./build/exe/Z3GatewayHost(emberRunEvents+0x7c) [0x4260cb]
-
./build/exe/Z3GatewayHost(emberRunTask+0x3b) [0x42611c]
-
./build/exe/Z3GatewayHost(emberAfRunEvents+0x1e) [0x45730d]
-
./build/exe/Z3GatewayHost(emberAfMain+0xf7) [0x462dbc]
-
./build/exe/Z3GatewayHost(main+0x2a) [0x44c00e]
-
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f6a674ea840]
-
./build/exe/Z3GatewayHost(_start+0x29) [0x41ee49]
阅读(1817) | 评论(0) | 转发(0) |