Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <unwind.h> // GCC's internal unwinder, part of libgcc
  2. _Unwind_Reason_Code trace_fcn(struct _Unwind_Context *ctx, void *d)
  3. {
  4.   int *depth = (int*)d;
  5.   printf("\t#%d: program counter at %08x\n", *depth, _Unwind_GetIP(ctx));
  6.   (*depth)++;
  7.   return _URC_NO_REASON;
  8. }
  9.  
  10. void print_backtrace_here()
  11. {
  12.   int depth = 0;
  13.   _Unwind_Backtrace(&trace_fcn, &depth);
  14. }
  15.  
  16. int func3() { print_backtrace_here(); return 0; }
  17. int func2() { return func3(); }
  18. int func1() { return func2(); }
  19. int main()  { return func1(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement