Why is "-a" added when debugging

607 Views Asked by At

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

There are 1 best solutions below

3
On BEST ANSWER

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.