1. debug by gdb:html
download the runtime-gdb file.git
$ wget -q -O - https://golang.org/src/runtime/runtime-gdb.py |grep '<span id="L' > runtime-gdb.pygithub
$ sed -i -e "s/<span.*span>//g" -e "s/<pre>//g" -e "s/^\t//g" -e 's/"/"/g' -e "s/'/'/g" -e "s/>/>/g" -e "s/</</g" -e "s/amp;//g" runtime-gdb.py bash
linux 下应该有脱字符处理工具(iconv)。 或者wget 自己应该能处理掉脱字符。ide
run gdb by: 工具
$ $GOROOT=`go env |grep GOROOT |cut -d "=" -f2`ui
$ gdb your_bin -d $GOROOTidea
$ gdb cpuinfo_main -d `go env |grep GOROOT |cut -d "=" -f2`
source ~/go/src/runtime/runtime-gdb.py
发现最新的golang1.6已经自带了runtime-gdb.py
进入gdb
(gdb) add-auto-load-safe-path /usr/local/go/src/runtime/runtime-gdb.py
echo "set auto-load safe-path /" > line to your configuration file "/home/shaohef//.gdbinit".
直接运行
$ gdb your_bin
2. godebug
Download:
$ go get -u github.com/mailgun/godebug
将 _ = "breakpoint" 插入代码。
build godbug
$ go build
mv godbug to goroot bin
$ sudo cp godebug /usr/local/go/bin/
$ debug
godbug run your go_file.
3. Go语言debug调试
4. 采用idea IDE环境。
5. 使用Delve进行Golang代码的调试
使用Delve调试test case
dlv test --build-flags='github.com/dlsniper/u/tmp/mypack' -- -test.run ^TestHello$
https://github.com/derekparker/delve/issues/422