Skip to content

Instantly share code, notes, and snippets.

@devymex
Created November 16, 2020 14:51
Show Gist options
  • Save devymex/95a51cd12afdb6f0d0357f97cb71b79c to your computer and use it in GitHub Desktop.
Save devymex/95a51cd12afdb6f0d0357f97cb71b79c to your computer and use it in GitHub Desktop.
trace call stack
#include <execinfo.h>
void print_trace (void) {
void *ppArrays[256];
int nTraceNum = backtrace(ppArrays, sizeof(ppArrays) / sizeof(ppArrays[0]));
char **ppSymbols = backtrace_symbols(ppArrays, nTraceNum);
if (ppSymbols != NULL) {
printf("Obtained %d stack frames.\n", nTraceNum);
for (int i = 0; i < nTraceNum; i++) {
printf("%s\n", ppSymbols[i]);
}
}
free(ppSymbols);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment