diff options
Diffstat (limited to 'libgo/runtime/go-traceback.c')
-rw-r--r-- | libgo/runtime/go-traceback.c | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/libgo/runtime/go-traceback.c b/libgo/runtime/go-traceback.c index 2ff2ce3..4e99ca7 100644 --- a/libgo/runtime/go-traceback.c +++ b/libgo/runtime/go-traceback.c @@ -6,57 +6,37 @@ #include "config.h" -#include "unwind.h" - #include "runtime.h" #include "go-string.h" -static _Unwind_Reason_Code -traceback (struct _Unwind_Context *context, void *varg) +/* Print a stack trace for the current goroutine. */ + +void +runtime_traceback () { - int *parg = (int *) varg; - uintptr pc; - int ip_before_insn = 0; - struct __go_string fn; - struct __go_string file; - int line; - -#ifdef HAVE_GETIPINFO - pc = _Unwind_GetIPInfo (context, &ip_before_insn); -#else - pc = _Unwind_GetIP (context); -#endif - - if (*parg > 100) - return _URC_END_OF_STACK; - ++*parg; - - /* FIXME: If PC is in the __morestack routine, we should ignore - it. */ - - /* Back up to the call instruction. */ - if (!ip_before_insn) - --pc; - - if (!__go_file_line (pc, &fn, &file, &line)) - return _URC_END_OF_STACK; - - if (runtime_showframe (fn.__data)) - { - runtime_printf ("%s\n", fn.__data); - runtime_printf ("\t%s:%d\n", file.__data, line); - } + uintptr pcbuf[100]; + int32 c; - return _URC_NO_REASON; + c = runtime_callers (1, pcbuf, sizeof pcbuf / sizeof pcbuf[0]); + runtime_printtrace (pcbuf, c); } -/* Print a stack trace for the current goroutine. */ - void -runtime_traceback () +runtime_printtrace (uintptr *pcbuf, int32 c) { - int c; + int32 i; - c = 0; - _Unwind_Backtrace (traceback, &c); + for (i = 0; i < c; ++i) + { + struct __go_string fn; + struct __go_string file; + int line; + + if (__go_file_line (pcbuf[i], &fn, &file, &line) + && runtime_showframe (fn.__data)) + { + runtime_printf ("%s\n", fn.__data); + runtime_printf ("\t%s:%d\n", file.__data, line); + } + } } |