2012-05-17 05:30:25 +00:00
|
|
|
/* 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"
|
|
|
|
|
2012-05-24 21:07:18 +00:00
|
|
|
/* Print a stack trace for the current goroutine. */
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime_traceback ()
|
2012-05-17 05:30:25 +00:00
|
|
|
{
|
2012-05-24 21:07:18 +00:00
|
|
|
uintptr pcbuf[100];
|
|
|
|
int32 c;
|
2012-05-17 05:30:25 +00:00
|
|
|
|
2012-05-24 21:07:18 +00:00
|
|
|
c = runtime_callers (1, pcbuf, sizeof pcbuf / sizeof pcbuf[0]);
|
2013-01-30 01:37:13 +00:00
|
|
|
runtime_printtrace (pcbuf, c, true);
|
2012-05-17 05:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-30 01:37:13 +00:00
|
|
|
runtime_printtrace (uintptr *pcbuf, int32 c, bool current)
|
2012-05-17 05:30:25 +00:00
|
|
|
{
|
2012-05-24 21:07:18 +00:00
|
|
|
int32 i;
|
2012-05-17 05:30:25 +00:00
|
|
|
|
2012-05-24 21:07:18 +00:00
|
|
|
for (i = 0; i < c; ++i)
|
|
|
|
{
|
2012-11-01 03:02:13 +00:00
|
|
|
String fn;
|
|
|
|
String file;
|
2012-11-06 18:28:21 +00:00
|
|
|
intgo line;
|
2012-05-24 21:07:18 +00:00
|
|
|
|
|
|
|
if (__go_file_line (pcbuf[i], &fn, &file, &line)
|
2013-01-30 01:37:13 +00:00
|
|
|
&& runtime_showframe (fn, current))
|
2012-05-24 21:07:18 +00:00
|
|
|
{
|
2012-06-07 06:34:52 +00:00
|
|
|
runtime_printf ("%S\n", fn);
|
2012-11-06 18:28:21 +00:00
|
|
|
runtime_printf ("\t%S:%D\n", file, (int64) line);
|
2012-05-24 21:07:18 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-17 05:30:25 +00:00
|
|
|
}
|