github.com/searKing/golang/go@v1.2.117/runtime/cgosymbolizer/symbolizer.go (about) 1 // Copyright 2021 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package cgosymbolizer provides a cgo symbolizer based on libbacktrace. 6 // This will be used to provide a symbolic backtrace of cgo functions. 7 // This package does not export any symbols. 8 // To use it on all platforms, add a line like 9 // 10 // import _ "github.com/searKing/golang/go/runtime/cgosymbolizer" 11 // go build main.go 12 // 13 // Advance Usage can be set by go build tags: 14 // 15 // BOOST_STACKTRACE_USE_WINDBG 16 // BOOST_STACKTRACE_USE_WINDBG_CACHED 17 // BOOST_STACKTRACE_USE_BACKTRACE 18 // BOOST_STACKTRACE_USE_ADDR2LINE 19 // BOOST_STACKTRACE_USE_NOOP 20 // 21 // all tags defined in https://www.boost.org/doc/libs/develop/doc/html/stacktrace/configuration_and_build.html 22 // 23 // go build -tags BOOST_STACKTRACE_USE_BACKTRACE main.go 24 // 25 // somewhere in your program. 26 // for linux only, you can use `cgosymbolizer` by ianlancetaylor instead. 27 // 28 // import _ "github.com/ianlancetaylor/cgosymbolizer" 29 package cgosymbolizer 30 31 // extern void cgoTraceback(void*); 32 // extern void cgoSymbolizer(void*); 33 import "C" 34 35 import ( 36 "runtime" 37 "unsafe" 38 ) 39 40 func init() { 41 runtime.SetCgoTraceback(0, unsafe.Pointer(C.cgoTraceback), nil, unsafe.Pointer(C.cgoSymbolizer)) 42 } 43 44 //// PreviousStacktrace returns a human readable stacktrace 45 //func PreviousStacktrace() string { 46 // stacktraceChars := C.CGO_PreviousStacktrace() 47 // defer C.free(unsafe.Pointer(stacktraceChars)) 48 // return C.GoString(stacktraceChars) 49 //}