Answer: How to know caller function when tracing assertion failure
answer re: How to know caller function when tracing assertion failure Mar 4 '12 8 See backtrace(). e.g. #include #include 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… Open Full Answer
See backtrace()
.
e.g.
#include
#include
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
…