backtrace代码里获取调用堆栈
介绍用法
[1] http://man7.org/linux/man-pages/man3/backtrace.3.html
[2] https://www.gnu.org/software/libc/manual/html_node/Backtraces.html
[3] https://www.cnblogs.com/mickole/p/3246702.html
代码
void PrintTrace() {
int nptrs;
void *buffer[200];
char **strings;
nptrs = backtrace(buffer, 200);
strings = backtrace_symbols(buffer, nptrs);
if (strings != NULL) {
for (int j = 0; j < nptrs; j ++)
LOG(INFO) << strings[j] << endl;
}
LOG(INFO) << "PrintTrace" << endl;
free(strings);
}