27

I am trying out GoLand and hear that the debugger is supposedly awesome, but I can’t find any documentation explaining how to set it up (GoLand is in preview stage, so that’s not really surprising). My use case: I am writing a REST API to which I send requests using curl. Could someone please tell me, step by step, how to get started with the debugger ?

[edit 1] (moved from comment) When I click Run/Debug (or Run/Run), a window is displayed, asking me to edit configurations. I am given a choice of several kinds of configurations, I try to choose "Go application" but the Debug button never is grayed and I can't get it to become clickable. I am very new to GoLand, I may be missing something obvious, but I can’t find whatever settings are missing.

[edit 2] It turns out that my workspace did not conform to the Go specifications : my code was not in a directory named src. Now that it is the case, I can click Run/Debug and GoLand seems to be doing the right thing, except it doesn’t stop at breakpoints or otherwise behave like a debugger, my code just runs.

[edit 3] Tried again, and it works. Sort of. I have no idea why it works now, even though it didn’t previously and I didn’t change anything. Now breakpoints work at some lines, and not at others. Or the debugger stops at the breakpoint, but I wait forever for the list of variables to be loaded. Well, it is a preview, after all...

[edit 4] I was notified just today that a new version of GoLand was available. I upgraded, and debugging is working well for me now.

MrDuk
  • 16,578
  • 18
  • 74
  • 133
Zoyd
  • 3,449
  • 1
  • 18
  • 27
  • The debugger looks like it "just works". What problem are you having? – JimB Jan 11 '17 at 15:00
  • 1
    @zoyd I'm sorry you have issues with debugging. Could you please share more details about your project / setup? What's the OS that you are running and which Go version? And if the project is open-source then a link to it would be great. Also it would help to have a way to reproduce this. Also Gogland uses Delve under the hood as a debugging backend and depending on you Go version things might be broken or not. – dlsniper Jan 11 '17 at 22:47
  • Setting up the Go structure is good information for the newbies to Gogland. – Steve Butler Jan 24 '17 at 04:01
  • I'm able to run but I'm not able to debug yet. I got this message: Error running Build hello.go and run: Cannot find runner for Build hello.go and run – Vincent Jan 26 '17 at 15:44
  • @Vincent I suggest you open a new question for your particular problem. – Zoyd Jan 30 '17 at 08:38
  • I noticed the same behavior. The first time I debugged an application, the breakpoints didn't work, but then after running it 2 or 3 times it seemed to work fine. Using OSX 10.10.5, go 1.7.4, Gogland 1.0 EAP, project is not open source. – stephenbez Jan 30 '17 at 23:53
  • Hey, Can you share your code or your repo? Do you have a delvet installed? – Ricardo Cunha Feb 24 '17 at 18:40
  • Thanks for your interest, but again, it now works. It may have been a temporary problem in that (now outdated) version of Gogland. – Zoyd Feb 24 '17 at 18:55
  • 1
    Just updated to the June 9th version: debugger in Gogland is just a joke. I understand that it is an early bird version but, seriously JB guys... even the Hello Word fails. – cvigo Jun 11 '17 at 21:04

7 Answers7

12

GoLand will not enable the debug action (although run is available) if your code does not reside inside src. There is no warning about this, so it might be really a pain to solve this.

Additionally, depending on your project’s structure it might be possible, that debugging is still not working. In that case, it might help to remove all run configurations and create a new one. There’s is a bug report about this behavior.

PS: Although the OP mentions the first part in an edit of the question, but it think it’s worth mentioning in an answer.

Black Frog
  • 11,595
  • 1
  • 35
  • 66
Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • 1
    That is one of the most inane and pointless requirements I've seen in quite some time. Why is an IDE (or the language itself) forcing a particular folder name on me? Thank you for the answer, but it's frustrating that I'm now going to own our entire server code if/when I check in the folder name change... – iamtheddrman Mar 28 '17 at 20:43
  • It's still an EAP, so there might already be a bug report about this. But even worse, it seems that a ’src’ directory doesn't always work. There seems to be another requirement, but I still have to find out which one. – Koraktor Mar 28 '17 at 20:49
  • 2
    After doing some additional research, it appears that it's actually the language that demands your source code be in a src folder. It can technically work without it, but you have to jump through additional hoops. Given that there's no real package management, it seems like a ridiculous design decision to have all of the code you ever work on in a single folder hierarchy. Working on multiple branches of the same repos becomes next to impossible, and that's a reality at every company I've ever worked for. – iamtheddrman Mar 29 '17 at 13:30
8

Things changed in goland since @Jamillo Santos added his reply.

To start with, there's no more "Go Application".

The easiest way is to locate the file containing the main() function. There should be a small triangle pointing to it, like in the attached screenshot: main function declaration

When you click on the small green triangle, you get a menu with Run/Debug options. Each will create a go build configuration.

You can edit that go build configuration and add the program arguments for your application. For example, if your program have a command line argument of --arg=value you can add it like this: enter image description here

Elad Tabak
  • 2,317
  • 4
  • 23
  • 33
6

I was facing this same issue and I solved by using the "Go Application" configuration (at the Run/Debug Configurations window), instead of the "Go Single File" configuration.

So, go to the upper right corner of the Gogland and "Edit configurations".

Opening the Run/Debug Configurations

Then, add a new configuration using the "Go Application" profile.

Run/Debug Configurations window

After saving, you should be able to debug your code. o/

An easy way to enable this configuration is to use the @user1793301 method and right click on the file you want to run and select "Debug 'go run .go'".


POSSIBLE EXPLANATION

NOTICE: I did not look any further details about it.

Fact: "Go Application" configuration does build the binary executable before running it.

Fact: I could see looking at the console output (inside of the Goglang) is that the IDE uses the DLV as debugging tool.

Fact: I found a dlv debug at the DLV documentation and it seems to compile and debug the code.

Hypothesis: The guys from Jetbrains did not implement it. Or at least not YET.

Jota Santos
  • 1,169
  • 10
  • 12
4

On version 2019.1.1 there's no more Go Application. Use Go Build instead. Here I am debugging a single script file, but if you have a server app or smth, just point to the main app file:

enter image description here

Notice that in the Files field you have to specify the actual file path. You can put more files (if you want to have more starting points) by separating them with a pipe |. For each file you want to be able to debug, you need to specify the full path.

Again, if you are debugging a server app or something else, that has a single starting point, you only need the startup file specified in the config. :)

Milkncookiez
  • 6,817
  • 10
  • 57
  • 96
1

I had this exact problem.

Deleted and recreated the Debug run configuration. Debugging then worked perfectly.

Larsern
  • 11
  • 2
1

I followed the following procedure to start my golang server in debug mode. (You might want to use some other method than creating a makefile for starting your server maybe)

  1. Create a makefile
  2. Define your server/worker startup command in the file
  3. Run it by creating a new configuration for Makefile
  4. Go to Run -> Attach to process -> choose your running server

This will attach the debugger to your process. Note:

  • You might need to restart your server for this to work.
  • The IDE will ask you to install gops, do install it. Without installing gops you won't see any running process.
Satya
  • 1,569
  • 8
  • 13
-1

I right click on project (main.go inside) and choose "Debug ..." and it work

Pang
  • 9,564
  • 146
  • 81
  • 122