How to find out which Go version built your binary

Source: Internet
Author: User
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

gdbwas 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:

    1. OS X have a built in WiFi scanner
    2. Introducing profile, Super simple profiling for Go programs
    3. Cross compilation just got a whole IoT better in Go 1.5
    4. Simple profiling package moved, updated
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.