Nice trick Keith. How quickly I have forgotten that gdb exists.
On Sun, Dec 6, 2015 at 11:06 AM, <
kei...@alum.mit.edu> wrote:
> The official way to get the version at runtime is runtime.Version. It reads
> from the variable runtime.buildVersion. If you're lucky enough that that
> variable was not dead-code eliminated, you can do:
>
> package main
>
> import "runtime"
>
> func main() {
> println(runtime.Version())
> }
>
>> go build version.go
>> ./version
> devel +8e496f1 Thu Nov 5 15:41:05 2015 +0000
>> gdb version
> (gdb) print 'runtime.buildVersion'
> $1 = 0x47e3c0 "devel +8e496f1 Thu Nov 5 15:41:05 2015 +0000"
>
> That should be more robust than using strings. If strings doesn't return
> something with 'devel' or 'go1.' in it, though, you're probably out of luck.
> runtime.buildVersion has almost certainly been dead-code eliminated.
>
> Maybe we should always keep this variable live? Wouldn't be hard to do,
> I'll add an issue to make this happen for 1.7.