前提:本文假定你的mac已经配置好GOROOT和GOPATH 2个环境变量!!!
下载dlv
命令行上操作: $ git clone https://github.com/go-delve/delve.git $GOPATH/src/github.com/go-delve/delve
注意:如果你本地已经下载过dlv,可以删除重新下载(先备份好),git安装自己搞定,很简单。
下载完成如下所示
localhost:~ zhenhua$ git clone https://github.com/go-delve/delve.git $GOPATH/src/github.com/go-delve/delve Cloning into ‘/Users/zhenhua/go/src/github.com/go-delve/delve’… remote: Enumerating objects: 21408, done. remote: Counting objects: 100% (1612/1612), done. remote: Compressing objects: 100% (987/987), done. remote: Total 21408 (delta 870), reused 1186 (delta 582), pack-reused 19796 Receiving objects: 100% (21408/21408), 28.09 MiB | 89.00 KiB/s, done. Resolving deltas: 100% (14223/14223), done.
在命令行中cd 到 dlv下载所在目录:
delve zhenhua$ make install Password: go install -tags=macnative “-ldflags=-s -X main.Build=9013a121d8bc6359018bccfaa1f256a8870d01c7” github.com/go-delve/delve/cmd/dlv codesign -s dlv-cert /Users/zhenhua/go/bin/dlv
此时可以在你的GOPATH/bin目录下看到dlv可执行文件
敲入dlv验证安装成功
$ dlv 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. Usage: …中间省略一大段… Additional help topics: dlv backend Help about the --backend flag. dlv log Help about logging flags. dlv redirect Help about file redirection. Use “dlv [command] --help” for more information about a command.。
此时dlv在本地磁盘上的目录结构如下
FYI: 我mac机器的GOPATH为 /Users/zhenhua/go, 正是对应下图的go文件夹
注意上图中多了一个文件夹,请往下看!
此时打开你的goland,打开一个项目,设置好断点,启动项目,你会发现如下错误:
err running program …"/Users/xxx/go/delve/delve/cmd/dlv/mac/dlv" (in directory “<你的本地go项目路径>”): error=2, No such file or directory…
注意错误提示,缺少 /Users/xxx/go/delve/delve/cmd/dlv/mac/dlv文件!
关键点:把你在生成好的、存在于$GOPATH/bin目录下的dlv文件复制到 错误提示中提到的目录中,如我上面截图所示,比起刚安装编译发的dlv正是多出了我复制的mac目录及dlv文件。
依据提示在相应目录下新建mac文件夹,把dlv文件复制进来,ok!再次启动goland 项目,就可以调试你的项目了,完美!截图如下:
|