Created
February 21, 2018 19:01
-
-
Save moonheart08/733415ae14eb1d4cc1079ab3b51c293f to your computer and use it in GitHub Desktop.
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
void print_backtrace() { | |
unw_cursor_t cursor; unw_context_t uc; | |
unw_word_t ip, sp, offset; | |
char buffer[1024]; // Lets make sure there's lots of space. | |
unw_getcontext(&uc); | |
unw_init_local(&cursor, &uc); | |
while (unw_step(&cursor) > 0) { | |
unw_get_reg(&cursor, UNW_REG_IP, &ip); | |
unw_get_reg(&cursor, UNW_REG_SP, &sp); | |
if (!unw_get_proc_name(&cursor, buffer, 1024, &offset)) { | |
printf("%s (Address: %p, Stack: %lx)\n", buffer, (void*) ip, (long) sp); | |
} else { | |
printf("Failed to symbolize (Address: %p, Stack: %lx)\n", (void*) ip, (long) sp); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment