Last active
August 29, 2015 14:05
-
-
Save benwaffle/81a9ac36b5002a337f71 to your computer and use it in GitHub Desktop.
view a stack trace in C
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
CFLAGS=-g | |
LDFLAGS=-lunwind -lunwind-x86_64 | |
all: stacktrace |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <libunwind.h> | |
void show_backtrace(void) | |
{ | |
unw_context_t uc; unw_getcontext(&uc); | |
unw_cursor_t cursor; unw_init_local(&cursor, &uc); | |
unw_word_t offp; | |
char proc_name[1024]; | |
while (unw_step(&cursor) > 0) | |
if (!unw_get_proc_name(&cursor, proc_name, 1024, &offp)) | |
puts(proc_name); | |
} | |
int main() | |
{ | |
show_backtrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment