Answer: How to know caller function when tracing assertion failure
Dobby33

Dobby33 @dobby33

Joined:
Feb 8, 2025

Answer: How to know caller function when tracing assertion failure

Publish Date: Feb 25
0 1

See backtrace().

e.g.

#include <execinfo.h>
#include <stdio.h>

void bar() {
  void* callstack[128];
  int i, frames = backtrace(callstack, 128);
  char** strs = backtrace_symbols(callstack, frames);
  for (i = 0; i < frames; ++i) {
    printf("%s\n", strs[i]);
  }
  free(strs);
}

int foo() {
  bar();
  return 0;
}

int main() {
  foo();
  return

Comments 1 total

Add comment