#include #if KF_GNU #include #endif void kf_printbacktrace(FILE *file) { #if KF_GNU static const int maxtracelen = 128; void *trace[maxtracelen]; int size = backtrace(trace, maxtracelen); char **strings = backtrace_symbols(trace, size); if (strings) { fprintf(file, "backtrace: (%d frames)\n", size); for (int i = 0 ; i < size ; i++) fprintf(file, " %d: %s\n", size-i, strings[i]); } else { fprintf(file, "failed to obtain backtrace\n"); } free(strings); #else fprintf(file, "kf_printbacktrace requires GNU extensions (execinfo.h)\n"); #endif }