5

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?

07_05_GuyT
  • 2,787
  • 14
  • 43
  • 88
  • Have you tried delve's `attach` command? – JimB Apr 09 '18 at 12:40
  • @JimB - i've tried with new Goland attach to local process and I was able to see the process in the opend dialog but wasnt able debug it getting error `"could not attach to pid 97234: EOF"` – 07_05_GuyT Apr 09 '18 at 12:41
  • @JimB - I've `delve` debugger installed but I use it from `vsCode` and `Goland` to debug internally , can you please provide which steps should I dot to try it with the attach command and I'll do it ASAP – 07_05_GuyT Apr 09 '18 at 12:44
  • It's possible you're seeing this: https://github.com/derekparker/delve/issues/1165 -- Try it from the command line first so you know if it's an issue with the editor integration, or the tools themselves. – JimB Apr 09 '18 at 12:55

1 Answers1

5

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.

dlsniper
  • 7,188
  • 1
  • 35
  • 44
  • Thanks a lot 1+ , another question in case I use the workaround how it should work? I open cli and execute the binary and then I go to Goland and use attach to local process but Im losing some time until I click on the process dialog and find the PID , should I do it differently ? – 07_05_GuyT Apr 09 '18 at 14:45
  • You answer my first question and I close it , it will be great if you can have a look at the comment ...thanks – 07_05_GuyT Apr 09 '18 at 18:06
  • We just released an update for the IDE which should make debugging possible again, without any workaround from you. Please try it, and if it's still not working comment back in the issue I linked. Thank you and sorry for the inconvenience! – dlsniper Apr 09 '18 at 18:21
  • Thanks, just two question: should I remove the `Use native backend` after the update ? – 07_05_GuyT Apr 09 '18 at 18:56
  • just to verify , in case i've very small go binary which I need to debug , I need to run this bin and in parallel use the option `run->attach local process` , until I'll do it the bin will finish to run..., so how can I make this work with the latest Goland? – 07_05_GuyT Apr 09 '18 at 18:59
  • Yes, you should br able to remove the `Use native backend` workaround after the update. I don't understand the second question, can you please either open an issue or ping me on twitter/Gophers Slack at @dlsniper? Thank you. – dlsniper Apr 10 '18 at 04:02
  • 1
    The latest Goland 2018.1.1 should have the OSX issue fixed. – Heiko Rupp Apr 11 '18 at 15:42