Search code examples
godebuggingidegolanddelve

Is it possible to debug pre-build go executables with GoLand?


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.


Solution

  • 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.