This is a sample program that tests output on a panicking go program based on different GOTRACEBACK
settings. There are several levels that control the amount of output generated - none
, single
, all
, system
- each with it's own aliases. More information can be found at https://golang.org/pkg/runtime/.
env GOTRACEBACK=none go run main.go
This should give the same output as env GOTRACEBACK=0 go run main.go
panic: f3
exit status 2
env GOTRACEBACK=single go run main.go
This should give the same output as simply running go run main.go
panic: f3
goroutine 4 [running]:
main.f3()
/Users/zihow.poh/main.go:17 +0x39
created by main.f2
/Users/zihow.poh/main.go:13 +0x35
exit status 2
env GOTRACEBACK=all go run main.go
This should give the same output as env GOTRACEBACK=1 go run main.go
panic: f3
goroutine 4 [running]:
main.f3()
/Users/zihow.poh/main.go:17 +0x39
created by main.f2
/Users/zihow.poh/main.go:13 +0x35
goroutine 1 [select (no cases)]:
main.main()
/Users/zihow.poh/main.go:5 +0x26
exit status 2
env GOTRACEBACK=system go run main.go
This should give the same output as env GOTRACEBACK=2 go run main.go
as well as env GOTRACEBACK=crash go run main.go
. From the documentation, GOTRACEBACK=crash is like “system” but crashes in an operating system-specific manner instead of exiting. For example, on Unix systems, the crash raises SIGABRT to trigger a core dump.
panic: f3
goroutine 18 [running]:
panic(0x1059780, 0x107b020)
/usr/local/go/src/runtime/panic.go:565 +0x2c5 fp=0xc000064fc0 sp=0xc000064f30 pc=0x1022b65
main.f3()
/Users/zihow.poh/main.go:17 +0x39 fp=0xc000064fe0 sp=0xc000064fc0 pc=0x104eb29
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000064fe8 sp=0xc000064fe0 pc=0x1048d81
created by main.f2
/Users/zihow.poh/main.go:13 +0x35
goroutine 1 [select (no cases)]:
runtime.gopark(0x0, 0x0, 0x100a, 0x1)
/usr/local/go/src/runtime/proc.go:301 +0xef fp=0xc000068758 sp=0xc000068738 pc=0x1024c1f
runtime.block()
/usr/local/go/src/runtime/select.go:102 +0x39 fp=0xc000068788 sp=0xc000068758 pc=0x1031e39
main.main()
/Users/zihow.poh/main.go:5 +0x26 fp=0xc000068798 sp=0xc000068788 pc=0x104ea96
runtime.main()
/usr/local/go/src/runtime/proc.go:200 +0x20c fp=0xc0000687e0 sp=0xc000068798 pc=0x102483c
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0000687e8 sp=0xc0000687e0 pc=0x1048d81
goroutine 2 [force gc (idle)]:
runtime.gopark(0x1071708, 0x10c0810, 0x1410, 0x1)
/usr/local/go/src/runtime/proc.go:301 +0xef fp=0xc000068fb0 sp=0xc000068f90 pc=0x1024c1f
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:307
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:250 +0xb7 fp=0xc000068fe0 sp=0xc000068fb0 pc=0x1024ac7
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000068fe8 sp=0xc000068fe0 pc=0x1048d81
created by runtime.init.5
/usr/local/go/src/runtime/proc.go:239 +0x35
goroutine 17 [GC sweep wait]:
runtime.gopark(0x1071708, 0x10c08e0, 0x140c, 0x1)
/usr/local/go/src/runtime/proc.go:301 +0xef fp=0xc0000647a8 sp=0xc000064788 pc=0x1024c1f
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:307
runtime.bgsweep(0xc000094000)
/usr/local/go/src/runtime/mgcsweep.go:70 +0x9c fp=0xc0000647d8 sp=0xc0000647a8 pc=0x1019c9c
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0000647e0 sp=0xc0000647d8 pc=0x1048d81
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:208 +0x58
exit status 2