c++ backtrace

秦时铭
2023-12-01

今天在看apollo代码时,看到了C++中打印backtrace的方法:

// 打印堆栈信息
void ShowStack() {
  int i;
  void *buffer[STACK_BUF_LEN];
  int n = backtrace(buffer, STACK_BUF_LEN);
  char **symbols = backtrace_symbols(buffer, n);
  AINFO << "=============call stack begin:================";
  for (i = 0; i < n; i++) {
    AINFO << symbols[i];
  }
  AINFO << "=============call stack end:================";
}

C语言程序调用栈:backtrace+backtrace_symbols+backtrace_symbols_fd_rtoax的博客-CSDN博客_backtrace_symbols_fd

 类似资料: