Skip to content

Instantly share code, notes, and snippets.

@ywkaras
Last active December 16, 2019 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ywkaras/d6c96c457165db924b466f037aae505d to your computer and use it in GitHub Desktop.
Save ywkaras/d6c96c457165db924b466f037aae505d to your computer and use it in GitHub Desktop.
Example of using backtrace functions
// Example of how to use GCC backtrace functions (in a plugin).
#include <cstdlib>
extern "C" int backtrace(void **frame_list, int size);
extern "C" char ** backtrace_symbols(void * const *frame_list, int size);
// ...
{
TSDebug(PIName, "Stack Dump:");
void *frame_list[200];
int num_frames = backtrace(frame_list, 200);
if (num_frames > 0) {
char **names = backtrace_symbols(frame_list, num_frames);
char **save_names = names;
do {
TSDebug(PIName, *(names++));
} while (--num_frames);
free(save_names);
}
}
// https://www.gnu.org/software/libc/manual/html_node/Backtraces.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment