Can you debug pre-build go executables?

Answered

Hello guys, I am wondering if GoLand can use the dlv exec command https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_exec.md for debugging.

The reason we need this is because we have a complicated build process with CGO and we can't create a run configuration that can work for debugging.

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.

Thanks in advance.

0
1 comment
Official comment

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.

Please sign in to leave a comment.