Skip to content

Instantly share code, notes, and snippets.

@benwaffle
Last active August 29, 2015 14:05
Show Gist options
  • Save benwaffle/81a9ac36b5002a337f71 to your computer and use it in GitHub Desktop.
Save benwaffle/81a9ac36b5002a337f71 to your computer and use it in GitHub Desktop.
view a stack trace in C
CFLAGS=-g
LDFLAGS=-lunwind -lunwind-x86_64
all: stacktrace
#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