Go Tools 101
-
We can use command
go build -x
to show what happen in a build process.
-
We can use command
go build -race
to output Go binary files which support race detecting.
When a data race is found in running the outputted programs, a panic will occur.
- gcflags
-
We can use command
go build -gcflags="-S"
to show the Go assembly code of the built program.
-
We can use command
go build -gcflags="-l"
to disable function inline.
-
We can use command
go build -gcflags="-N"
to disable compiler optimizations (not including function inline).
-
We can use command
go build -gcflags="-d=ssa/check_bce/debug=1"
to check which lines
need bound checking.
-
We can use command
go build -gcflags="-B"
to disable bound checking.
Warning: this is very not recommended to use in production.
This flag may be not supported any more in later Go SDK versions.
-
We can use command
go build -gcflags="-m -m"
to check which variables escape to heap.
There can be one to four -m
s in the gcflags
option.
More -m
s, more information.
We can also write "-m -m"
as "-m=2"
.
-
We can use command
GOSSAFUNC=main go build
to output all SSA optimizations in a ssa.html
file.
-
we can use command
go tool objdump -s aFunction aProgram
to show the Go assembly code of
function aFunction
in the Go binary program aProgram
.
For example, go tool objdump -s main.main mygame
will print the Go assembly code
of the main
entry function in Go binary file mygame
.
-
We can use command
go tool nm aProgram
to show all the symbols in a Go binary file.
-
Online Go linter
-
talks: online presentation maker.