使用dlv调试”go get”命令

huangapple go评论68阅读模式
英文:

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 …

huangapple
  • 本文由 发表于 2021年7月17日 00:13:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/68412194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定