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);
}
本文详细介绍backtrace函数在C/C++中的使用方法,演示了如何通过backtrace和backtrace_symbols函数获取当前进程的调用堆栈信息,对于理解程序运行流程和进行错误定位具有重要作用。
3930

被折叠的 条评论
为什么被折叠?



