Skip to content

Instantly share code, notes, and snippets.

@jessetan
Last active December 3, 2024 08:33
Show Gist options
  • Select an option

  • Save jessetan/d64c996991c172a391da to your computer and use it in GitHub Desktop.

Select an option

Save jessetan/d64c996991c172a391da to your computer and use it in GitHub Desktop.
Print callstack trace from c++
// 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