Last active
December 3, 2024 08:33
-
-
Save jessetan/d64c996991c172a391da to your computer and use it in GitHub Desktop.
Print callstack trace from c++
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
| // Add #include <execinfo.h> to includes | |
| // START STACK TRACE | |
| void* tracePtrs[100]; | |
| int count = backtrace( tracePtrs, 100 ); | |
| char** funcNames = backtrace_symbols( tracePtrs, count ); | |
| // Print the stack trace | |
| printf("Stack trace:\n"); | |
| for( int ii = 0; ii < count; ii++) { | |
| printf("\t%s\n", funcNames[ii]); | |
| } | |
| // Free the string pointers | |
| free( funcNames ); | |
| // END STACK TRACE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment