Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up debugging in GoLand?

Tags:

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.

like image 556
Zoyd Avatar asked Jan 11 '17 13:01

Zoyd


People also ask

Can we set debug true with Go Build?

You can generate uncompressed debug information by using go build -ldflags=-compressdwarf=false . (For convenience you can put the -ldflags option in the GOFLAGS environment variable so that you don't have to specify it each time.)

How do I run code in GoLand?

Open the Run/Debug Configuration dialog in one of the following ways: Select Run | Edit Configurations from the main menu. With the Navigation bar visible (View | Appearance | Navigation Bar), choose Edit Configurations from the run/debug configuration selector. Press Alt+Shift+F10 and then press 0 .


2 Answers

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.

like image 194
Koraktor Avatar answered Sep 24 '22 05:09

Koraktor


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.

like image 30
Jota Santos Avatar answered Sep 22 '22 05:09

Jota Santos