Last active
April 30, 2020 07:54
-
-
Save Miliox/1d923989251001ca7aaece7d5a59f824 to your computer and use it in GitHub Desktop.
Simple stack trace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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