Last active
December 16, 2019 16:54
-
-
Save ywkaras/d6c96c457165db924b466f037aae505d to your computer and use it in GitHub Desktop.
Example of using backtrace functions
This file contains 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
// 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