summaryrefslogtreecommitdiff
path: root/libgo/runtime/go-traceback.c
blob: 2927351c8a975b740c69588d5c03580149c8399d (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
/* 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"

/* 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)
    {
      String fn;
      String file;
      intgo line;

      if (__go_file_line (pcbuf[i], &fn, &file, &line)
	  && runtime_showframe (fn.str))
	{
	  runtime_printf ("%S\n", fn);
	  runtime_printf ("\t%S:%D\n", file, (int64) line);
	}
    }
}