aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgo/gcc_traceback.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2015-12-11 17:16:48 -0800
committerIan Lance Taylor <iant@golang.org>2016-04-01 04:13:44 +0000
commitea306ae625d001a43ef20163739593a21be51f97 (patch)
tree9123485cd4112995217584ee66e39c6f584533b2 /src/runtime/cgo/gcc_traceback.c
parentb64f549ba95fb9115afb1db8ae594b9442c45a6e (diff)
downloadgo-ea306ae625d001a43ef20163739593a21be51f97.tar.gz
go-ea306ae625d001a43ef20163739593a21be51f97.zip
runtime: support symbolic backtrace of C code in a cgo crash
The new function runtime.SetCgoTraceback may be used to register stack traceback and symbolizer functions, written in C, to do a stack traceback from cgo code. There is a sample implementation of runtime.SetCgoSymbolizer at github.com/ianlancetaylor/cgosymbolizer. Just importing that package is sufficient to get symbolic C backtraces. Currently only supported on linux/amd64. Change-Id: If96ee2eb41c6c7379d407b9561b87557bfe47341 Reviewed-on: https://go-review.googlesource.com/17761 Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/cgo/gcc_traceback.c')
-rw-r--r--src/runtime/cgo/gcc_traceback.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/runtime/cgo/gcc_traceback.c b/src/runtime/cgo/gcc_traceback.c
new file mode 100644
index 0000000000..4fdfbe4d9f
--- /dev/null
+++ b/src/runtime/cgo/gcc_traceback.c
@@ -0,0 +1,29 @@
+// Copyright 2016 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.
+
+// +build cgo
+// +build linux
+
+#include <stdint.h>
+
+struct cgoTracebackArg {
+ uintptr_t Context;
+ uintptr_t* Buf;
+ uintptr_t Max;
+};
+
+// Call the user's traceback function and then call sigtramp.
+// The runtime signal handler will jump to this code.
+// We do it this way so that the user's traceback function will be called
+// by a C function with proper unwind info.
+void
+x_cgo_callers(uintptr_t sig, void *info, void *context, void (*cgoTraceback)(struct cgoTracebackArg*), uintptr_t* cgoCallers, void (*sigtramp)(uintptr_t, void*, void*)) {
+ struct cgoTracebackArg arg;
+
+ arg.Context = 0;
+ arg.Buf = cgoCallers;
+ arg.Max = 32; // must match len(runtime.cgoCallers)
+ (*cgoTraceback)(&arg);
+ sigtramp(sig, info, context);
+}