aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-traceback.c
blob: 4e99ca7d2f47924a2913fe44efb5bd20588d745d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* go-traceback.c -- stack backtrace for Go.

   Copyright 2012 The Go Authors. All rights reserved.
   Use of this source code is governed by a BSD-style
   license that can be found in the LICENSE file.  */

#include "config.h"

#include "runtime.h"
#include "go-string.h"

/* Print a stack trace for the current goroutine.  */

void
runtime_traceback ()
{
  uintptr pcbuf[100];
  int32 c;

  c = runtime_callers (1, pcbuf, sizeof pcbuf / sizeof pcbuf[0]);
  runtime_printtrace (pcbuf, c);
}

void
runtime_printtrace (uintptr *pcbuf, int32 c)
{
  int32 i;

  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);
	}
    }
}