调试时为什么要添加”-a”?

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

Why is "-a" added when debugging

问题

我有一个使用CGO导入(sqlite3)的项目。当我使用调试模式运行Go应用程序配置时,IDE会添加-a标志,导致所有内容都被重新构建。在我的情况下,它需要超过40秒才能开始运行。

我正在使用EAP 172.3968.42(9月4日)和Go 1.9 Release。

有没有办法告诉它不要添加-a标志?

当我在没有调试并且没有添加标志的情况下运行时,编译只需要3秒钟。
我不需要调试任何导入,只需要调试我的纯Go代码。

谢谢。

英文:

I have a project with a CGO import (sqlite3). When I am running a Go application configuration with debugging the IDE adds the -a flag which causes everything to be rebuilt. In my case it takes above 40 seconds for it to start running.

I am using EAP 172.3968.42 (Sep 4th) with Go 1.9 Release

Is there a way to tell it not to add the -a flag?

When I am running without debugging and the flag is not added it takes 3 seconds to compile.
I don't need to debug any imports, only my code which is in pure Go.

Thanks.

答案1

得分: 1

Gogland将使用"go build -a .... package/name ...."来构建调试二进制文件,以便进行调试。如果你想要旧的行为,那么你需要在设置 | 构建、执行、部署 | 调试器 | Delve 中切换“重新构建传递依赖项”。然而,这是不鼓励的,对于任何调试问题,你需要首先打开它,然后报告问题。这是因为Gogland将绕过Delve在运行"dlv debug package/name"时本应执行的操作。希望在Go 1.10中有更好的支持,但这也取决于Go团队的工作。

现在是更详细的版本:

你是正确的,使用EAP 12+时,由于改进的调试支持,编译速度有所下降。

发生的情况是,Go 1.9现在可以更好地编译传递依赖项,并关闭所有优化,这意味着Delve可以更好地工作于你的应用程序。

这意味着GOPATH/pkg和GOROOT/pkg中的所有内容都会被重新编译以进行调试,以确保没有意外包含启用优化的包。

如果发生这种情况,你可能最终会得到一个无法很好地进行调试的包,有时甚至可能是你的包之一。

不幸的是,目前禁用优化的构建无法进行缓存,这是由于"-a"的工作方式。这意味着目前无法使用"go build -i -a -gcflags '-N -l' ... package/name ..."。

当运行"dlv debug ... package/name ...."时,Delve本身会应用"-a"标志,所以虽然你可以在Gogland中关闭"-a"标志,但我建议不要这样做(或者在遇到任何错误时,你需要重新使用它进行调试,因为这不是Delve官方支持的模式)。

有关原始问题的链接,请参见:https://youtrack.jetbrains.com/issue/GO-4249

希望对你有所帮助。

英文:

Gogland will build the debug binary with "go build -a .... package/name ...." in order to debug it. If you want the old behavior, then you need to go in Settings | Build, Execution, Deployment | Debugger | Delve and toggle Rebuild transitive dependencies. However, this is discouraged and for any debugging issue you have you'll need to first turn that back on and then report the issue. This is because Gogland will bypass what Delve would otherwise do when running "dlv debug package/name". There are plans to have better support in Go 1.10, hopefully, but this depends on work from the Go team as well.

Now for the longer version:

You are correct, the compilation speed has degraded a bit when using the EAP 12+ because of improved debugging support.

What happened is that Go 1.9 can now do a better job at compiling the transitive dependencies with all the optimizations turned off which means Delve can work better on your application.

This means everything in GOPATH/pkg and GOROOT/pkg is recompiled for debugging in order to ensure that there's no package that has been included accidentally with the optimizations on.

If that would happen, then you could potentially end up with a package that does not debug as well, and sometimes that could even be one of your packages.

Unfortunately, for now, optimizations off builds are not cacheable, due to how "-a" works. This means "go build -i -a -gcflags '-N -l' ... package/name ... " is not possible at the moment.

Delve itself would apply the "-a" flag when running "dlv debug ... package/name .... " so, while you can turn the "-a" flag off in Gogland, I would advise against it (or you'd have to redo the debugging session using it in case you encounter any bugs since this is not a mode supported by Delve officially).

For a link to the original issue, please see: https://youtrack.jetbrains.com/issue/GO-4249

Hope this helps.

huangapple
  • 本文由 发表于 2017年9月5日 16:38:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/46050568.html
匿名

发表评论

匿名网友

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

确定