1 /* go-traceback.c -- stack backtrace for Go.
3 Copyright 2012 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
12 #include "go-string.h"
14 static _Unwind_Reason_Code
15 traceback (struct _Unwind_Context
*context
, void *varg
)
17 int *parg
= (int *) varg
;
19 int ip_before_insn
= 0;
20 struct __go_string fn
;
21 struct __go_string file
;
25 pc
= _Unwind_GetIPInfo (context
, &ip_before_insn
);
27 pc
= _Unwind_GetIP (context
);
31 return _URC_END_OF_STACK
;
34 /* FIXME: If PC is in the __morestack routine, we should ignore
37 /* Back up to the call instruction. */
41 if (!__go_file_line (pc
, &fn
, &file
, &line
))
42 return _URC_END_OF_STACK
;
44 if (runtime_showframe (fn
.__data
))
46 runtime_printf ("%s\n", fn
.__data
);
47 runtime_printf ("\t%s:%d\n", file
.__data
, line
);
50 return _URC_NO_REASON
;
53 /* Print a stack trace for the current goroutine. */
61 _Unwind_Backtrace (traceback
, &c
);