This is a creation in Article, where the information may have evolved or changed.
This is a short post describing the procedure for discovering which version of Go were used to compile a go binary.
This procedure relies on the fact, each Go program includes a copy of the version string reported by runtime.Version()
. Linker Magic ensures that this value would be present in the final binary irrespective of whether was called by the runtime.Version()
re Sulting program. The value in question are stored in the runtime.buildVersion
variable and can being recovered by a debugger.
The rest of this post describes the mechanisms for recovering the contents of the runtime.buildVersion
various platforms.
Linux/freebsd/openbsd/netbsd
If you ' re on a Linux or *BSD platform, you can recover the binary build version with gdb
.
% gdb $HOME/bin/godocgnu gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1Copyright (C) free software Foundation, inc.license gplv3+: GNU GPL version 3 or later
Darwin
The debugging situation on OS X isn't great, but here is the several options.
Gdb
gdb
was removed from the XCode toolchain following the switch from gcc
to llvm
. If you is running a version of XCode that have gdb
, you should used the instructions from the previous section.
Lldb
I ' ve not been able to find a shipping version of that lldb
can interpret the Go string
syntax. If I discover the correct incantation, I ' ll update this post. Until Then, usedelve
Delve
Delve can used to print the value of runtime.buildVersion
.
% DLV exec $HOME/bin/godoctype ' help ' for list of commands. (DLV) b main.mainbreakpoint 1 set at 0x15596eb for Main.main ()./golang.org/x/tools/cmd/godoc/main.go:156 (DLV) c> main . Main ()./golang.org/x/tools/cmd/godoc/main.go:156 (hits Goroutine (1): 1 total:1) (PC:0X15596EB) 151: } : } 153: log. Fatalf ("Too many redirects") 154:} 155:=> 156:func main () { 157: flag. Usage = Usage 158: flag. Parse () 159: playenabled = *showplayground 161: (DLV) P runtime.buildversion "go1.8.1"
Windows
No idea, sorry. If someone wants to figure out the correct WINDBG incantation, please let me know and I'll link to the post.
Related Posts:
- OS X have a built in WiFi scanner
- Introducing profile, Super simple profiling for Go programs
- Cross compilation just got a whole IoT better in Go 1.5
- Simple profiling package moved, updated