4

I am wondering if GoLand can use the dlv exec command for debugging.

The reason we need this is because we have a complicated build process with CGO, and it's impossible to create a run configuration that works.

Maybe attach to process could work, but it doesn't seem like a great solution.

VSCode has nice integration with dlv exec, but the IDE works too slow and buggy, I wish we could use GoLand.

Has anybody found a solution for this?

Thanks in advance.

3
  • AFAIK (unless it changed in the past couple of years), Delve works by annotating the code and compiling a modified binary (much like the profiler works). So you can't use it for pre-built binaries, you need the source code. Commented Aug 11, 2020 at 18:18
  • I don't know how delve works exactly, but the documentation for exec states: This command will cause Delve to exec the binary and immediately attach to it to begin a new debug session. Please note that if the binary was not compiled with optimizations disabled, it may be difficult to properly debug it. Please consider compiling debugging binaries with -gcflags="all=-N -l" on Go 1.10 or later, -gcflags="-N -l" on earlier versions of Go. Commented Aug 11, 2020 at 21:06
  • I assume all needed debugging information can be generated during the build process (at least for the go part of the code). For example, applications like gdlv and even VSCode can debug the binary. Commented Aug 11, 2020 at 21:11

1 Answer 1

4

You can use the same steps as in debugging a remote process.

Those steps are:

  • build the binary with go build -gcflags="all=-N -l" -o myApp and any other flags you might need for CGO/etc.
  • run the binary using dlv --listen=:2345 --headless=true --api-version=2 exec ./myApp
  • go to Run | Edit Configurations | + | Go Remote and create a new run configuration that connects to localhost on port 2345 (or any other port you specify in delve's --listen flag.
Sign up to request clarification or add additional context in comments.

4 Comments

Yes, thank you, I was looking for something like this exactly. We managed to use a standard run configuration, after a lot of hassle, but this works great and will be helpful.
Can you please help us understand where the run configuration caused issues? We'd love to know about it and see if we can improve it. youtrack.jetbrains.com/issues/Go for the tracker or find me on Twitter with the same username as here. Thanks!
Sure thing. In this case the problem is how specific our build process is. We compile at lest 5 cpp libraries with gcc using cgo, but some people on the team have to use Windows using the MinGW port of gcc, etc... So there are a lot of env variables, compiler options and applications themselves use a lot of flags. So getting all that correct in a run config, that is also multi-platform, is pretty hard. We have a custom build system that handles a lot of those complexities and we want to use it. In other words - debugging pre-build executables is the functionality we are looking for.
Thanks for the link though, there are a couple of other issues we experience that we might need help with, since we are rather new to GoLand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.