Search code examples
debugginggobinaryvisual-studio-codegoland

Debug Golang code and attach it to local process


Im having a Golang code which I create from it binary for mac via go build like:

build darwin amd64 myapp

Currently Im able to run the binary and see the logs.

Now I want to debug it , is there a way to debug the binary with Goland or Intellij or VSCode ? regular debug with delve is working from all the IDE's above but now I want to attach it to the binary process which I was able to run,Any idea if it possible?


Solution

  • If you use GoLand 2018.1+ you should be able to use the Run | Attach to Local Process feature and it will allow you to debug a running binary.

    I suggest that you compile the binary with all the optimizations turned off and compiled with Go 1.10+ in order to get the best debugging experience.

    Furthermore, the IDE can launch the binary and debug it in a single click, removing the need to perform multiple steps.

    One last issue that I can mention is that you currently will not be able to correctly debug Go apps via Delve, so regardless of which editor you use, due to a bug introduced by Apple in the latest developer tools. For more information please see the issue on our tracker: https://youtrack.jetbrains.com/issue/GO-5527 and on Delve's tracker: https://github.com/derekparker/delve/issues/1165

    Edit:

    The issue mentioned above was resolved in GoLand 2018.1.1.