aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/cgocall.go
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/cgocall.go
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/cgocall.go')
-rw-r--r--src/runtime/cgocall.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go
index 7a683d7524..7cffa83617 100644
--- a/src/runtime/cgocall.go
+++ b/src/runtime/cgocall.go
@@ -84,6 +84,10 @@ import (
"unsafe"
)
+// Addresses collected in a cgo backtrace when crashing.
+// Length must match arg.Max in x_cgo_callers in runtime/cgo/gcc_traceback.c.
+type cgoCallers [32]uintptr
+
// Call from Go to C.
//go:nosplit
func cgocall(fn, arg unsafe.Pointer) int32 {
@@ -109,6 +113,14 @@ func cgocall(fn, arg unsafe.Pointer) int32 {
mp.ncgo++
defer endcgo(mp)
+ // Allocate memory to hold a cgo traceback if the cgo call crashes.
+ if mp.cgoCallers == nil {
+ mp.cgoCallers = new(cgoCallers)
+ }
+
+ // Reset traceback.
+ mp.cgoCallers[0] = 0
+
/*
* Announce we are entering a system call
* so that the scheduler knows to create another