Skip to content

Instantly share code, notes, and snippets.

@Miliox
Last active April 30, 2020 07:54
Show Gist options
  • Save Miliox/1d923989251001ca7aaece7d5a59f824 to your computer and use it in GitHub Desktop.
Save Miliox/1d923989251001ca7aaece7d5a59f824 to your computer and use it in GitHub Desktop.
Simple stack trace
#include <execinfo.h>
#define PRINT_STACKTRACE(TAG) \
{ \
void* buffer[256]; \
int count = backtrace(buffer, 256); \
\
char** calls = backtrace_symbols(buffer, count); \
if (calls != nullptr) \
{ \
for (int i =0 ; i < count; i++) \
{ \
printf("%s %d:%s", TAG, i, calls[i]); \
} \
free(calls); \
} \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment