英文:
Debug "go get" with dlv
问题
我想用dlv
在模块感知模式下调试go get
命令。假设我有一个位于/some/dir/mymod
的Go模块。要在模块感知模式下使用go get
,我需要执行以下步骤:
$ cd /some/dir/mymod
$ go get
但是,如果我想用dlv
调试go
命令本身,我需要执行以下步骤:
$ cd /usr/local/go/src/cmd/go
$ dlv debug -- get [这里是一些参数]
如你所见,为了使用dlv
,我需要在要调试的模块中,但是为了使用go get
,我需要在要更新的模块中。所以问题是:我如何使用dlv
调试特定模块的go get
命令?
英文:
I want to debug go get
in module-aware mode with dlv
. Say I have a go module at /some/dir/mymod
. To use go get in module-aware mode I would have to do the following
$ cd /some/dir/mymod
$ go get
But if I want to debug the go command itself with dlv
I would have to do the following
$ cd /usr/local/go/src/cmd/go
$ dlv debug -- get [some args here]
As you see in order to use dlv
I need to be in the module that I want to debug, but in order to use go get
I need to be in the module that I want to update. So the question is: how can I debug go get
for a particular module with dlv
?
答案1
得分: 0
根据https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_debug.md的说明,dlv debug
命令会导致Delve“编译并开始调试当前目录中的主包,或者指定的包”(我强调了指定的包)。
所以你可以这样做:
cd /some/dir/mymod
dlv debug cmd/go -- get …
或者也可以这样:
cd /some/dir/mymod
dlv debug $(go env GOROOT)/src/cmd/go -- get …
英文:
According to https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_debug.md, dlv debug
causes Delve to “Compile and begin debugging main package in current directory, or the package specified” (emphasis mine).
So you should be able to do:
cd /some/dir/mymod
dlv debug cmd/go -- get …
or perhaps
cd /some/dir/mymod
dlv debug $(go env GOROOT)/src/cmd/go -- get …
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论