Stack traces: Difference between revisions

(Adds Clojure solution)
Line 680:
import (
"fmt"
"runtime/debug"
)
 
func main() {
stackTrace := debug.Stackmake([]byte, 1024)
// to print it to standard error
n := runtime.Stack(stackTrace, true)
debug.PrintStack()
stackTrace = stackTrace[:n]
// alternately to get it in a variable:
fmt.Printf("%s\n", stackTrace)
stackTrace := debug.Stack()
fmt.Printf("(%d bytes)\n", len(stackTrace))
}</lang>
outputs:
<pre>
goroutine 16 [running]:
/home/foo/test/test.go:12 (0x8048c26)
main: debug.PrintStackmain()
/tmpfs/gosandbox-efa5a722_5cfcad46_bebc14b4_0486dec5_bd9e34fc/prog.go:10 +0xa0
/home/foo/go/hg/src/pkg/runtime/386/asm.s:93 (0x8049b72)
 
mainstart: CALL main·main(SB)
goroutine 19 [runnable]:
/home/foo/go/hg/src/pkg/runtime/proc.c:149 (0x80531de)
runfinq()
goexit: runtime·goexit(void)
/hometmp/foosandbox/go/hg/src/pkg/runtime/386/asmmgc0.sc:93 (0x8049b72)2606
(227 bytes)
goexit: runtime·.goexit(void)
/hometmp/foosandbox/go/hg/src/pkg/runtime/proc.c:149 (0x80531de)1445
 
(227259 bytes)
</pre>
 
Anonymous user