1
0
mirror of https://github.com/ioacademy-jikim/debugging synced 2025-06-07 07:56:19 +00:00
debugging/01_day/backtrace/backtrace_6.c
2015-12-13 22:34:58 +09:00

25 lines
509 B
C

#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include "backtrace.h"
void print_gnu_backtrace()
{
unw_cursor_t cursor;
unw_context_t context;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
while (unw_step(&cursor) > 0) {
unw_word_t offset, pc;
char fname[64];
unw_get_reg(&cursor, UNW_REG_IP, &pc);
fname[0] = '\0';
(void) unw_get_proc_name(&cursor, fname, sizeof(fname), &offset);
printf ("%p : (%s+0x%x) [%p]\n", (void*)pc, fname, offset, (void*)pc);
}
}