Delve是Go语言的调试工具
安装
执行如下命令:
go get -u github.com/go-delve/delve/cmd/dlv
查看是否安装成功:
dlv version
如果没有dlv命令,常见问题是由于没有将dlv路径增加到PATH中,默认安装在GOPATH/bin路径下,或通过find命令进行查找确定具体安装路径
find / -name dlv 2>/dev/null
确定完安装路径后,将路径加入PATH中,或者将dlv拷贝到/usr/local/bin目录
PATH=$PATH:$DLV_PATH
或者
cp dlv /usr/local/bin
执行dlv version命令,出现如下情况表示安装成功:
user$ dlv version
Delve Debugger
Version: 1.6.0
Build: $Id: 8cc9751909843dd55a46e8ea2a561544f70db34d $
基本用法
先通过输入dlv或dlv --help来查看支持的命令
$ dlv --help
Delve is a source level debugger for Go programs.
Delve enables you to interact with your program by controlling the execution of the process,
evaluating variables, and providing information of thread / goroutine state, CPU register state and more.
The goal of this tool is to provide a simple yet powerful interface for debugging Go programs.
Pass flags to the program you are debugging using `--`, for example:
`dlv exec ./hello -- server --config conf/config.toml`
Usage:
dlv [command]
Available Commands:
attach Attach to running process and begin debugging.
connect Connect to a headless debug server.
core Examine a core dump.
dap [EXPERIMENTAL] Starts a TCP server communicating via Debug Ad