runtime: runtime.Caller should succeed even without debug info.
[gcc.git] / libgo / runtime / go-traceback.c
1 /* go-traceback.c -- stack backtrace for Go.
2
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. */
6
7 #include "config.h"
8
9 #include "runtime.h"
10 #include "go-string.h"
11
12 /* Print a stack trace for the current goroutine. */
13
14 void
15 runtime_traceback ()
16 {
17 uintptr pcbuf[100];
18 int32 c;
19
20 c = runtime_callers (1, pcbuf, sizeof pcbuf / sizeof pcbuf[0]);
21 runtime_printtrace (pcbuf, c);
22 }
23
24 void
25 runtime_printtrace (uintptr *pcbuf, int32 c)
26 {
27 int32 i;
28
29 for (i = 0; i < c; ++i)
30 {
31 struct __go_string fn;
32 struct __go_string file;
33 int line;
34
35 if (__go_file_line (pcbuf[i], &fn, &file, &line)
36 && runtime_showframe (fn.__data))
37 {
38 runtime_printf ("%S\n", fn);
39 runtime_printf ("\t%S:%d\n", file, line);
40 }
41 }
42 }