Does any golang interactive debugger exist?

DebuggingGo

Debugging Problem Overview


The title pretty much sums it up. I am trying out Go and I really miss being able to set breakpoints and step in/over/out as much as I want within an interactive environment. I know I can use gdb to debug Go but that is quite annoying compared to using an IDE that can plug into gdb for breakpointing.

I tried searching for one and could only find plugins or small IDEs that have syntax highlighting but no debugging.

Debugging Solutions


Solution 1 - Debugging

Update: Personally, while GDB works I'm not a fan of using it in Go and it will make you spit some blood. Check out some of the other answers for good alternatives.


Yes, of course :)

Go has a debugger (GDB)

Here is the official tutorial on how to use it.

If you'd like 'graphical debugging' (that is, setting breakpoints in the editor) some IDEs let you do that (with GDB in the background).

In specific, Eclipse, LiteIDE and Zeus all let you set breakpoints and debug from your coding environment (source). Here is a video on how to do it with Zeus.

Solution 2 - Debugging

GDB support for go has lots of issues that won't be fixed by the go team.

For more information, read the post by Rob Pike:

> Although we will endeavor to keep basic gdb functionality (stack traces, printing values) working on supported platforms, the ability to use the debugger to understand a Go program's full environment will likely never work, and improving gdb support is not a priority for the team.

They are looking for other debugging options but have no concrete plans by now. The documentation is outdated and the runtime-gdb.pyscript coming with go 1.2 does not work for a GDB that was compiled with python3 support (current Ubuntu for example).

Solution 3 - Debugging

Update 2017: the godebug project mentions below is now official replaced by derekparker/delve.


Original answer:

You now (March 2015) have another approach, based on instrumenting the code.

mailgun/godebug:

> godebug uses source code generation to instrument your program with debugging calls.
go tool cover takes a similar approach to code coverage.

> - When you run godebug, it parses your program, instruments function calls, variable declarations, and statement lines, and outputs the resulting code somewhere (currently either stdout or in place over your original files).

  • When you run this modified code, assuming you put a breakpoint somewhere, you can step through it and inspect variables.

> Coming later: evaluate arbitrary Go expressions and write to variables.


Update June 2015:

While it might not be as interactive as "some" might hope, it is still appreciated (and has "step into" feature).
See "Go has a debugger—and it's awesome!" (Cloudfare)

> here's the cool bit: instead of wrestling with half a dozen different ptrace interfaces that would not be portable, godebug rewrites your source code and injects function calls like godebug.Line on every line, godebug.Declare at every variable declaration, and godebug.SetTrace for breakpoints (i.e. wherever you type _ = "breakpoint").

> I find this solution brilliant.
What you get out of it is a (possibly cross-compiled) debug-enabled binary that you can drop on a staging server just like you would with a regular binary.

> When a breakpoint is reached, the program will stop inline and wait for you on stdin.

> It's the single-binary, zero-dependencies philosophy of Go that we love applied to debugging. Builds everywhere, runs everywhere, with no need for tools or permissions on the server.

ifdef GODEBUG  
    GOPATH="${PWD}" go install github.com/mailgun/godebug
    GOPATH="${PWD}" ./bin/godebug build -instrument "${GODEBUG}" -o bin/rrdns rrdns

> Debugging is just a make bin/rrdns GODEBUG=rrdns/... away.

Solution 4 - Debugging

UPDATE:

I have checked it out and am happy to report that Version: 2016.1.3, Build: 145.1617.8, Released: June 5, 2016 works with Delve! You can download it here: https://www.jetbrains.com/idea/download/. Also follow the Delve install instructions here: https://github.com/derekparker/delve/tree/master/Documentation/installation

It's a bit flaky. Just after I got the OSX login prompt the interactive debugging started working. Sometimes, I have to debug a simple .go program to kick start it. But it does work and is the best interactive debugging experience for Go that I've seen.

ORIGINAL POST:

Does any golang interactive debugger exist? Yes.

Does any golang interactive debugger, that is worth using, exist? No.

Configuring GDB on the mac is tedious, but doable.

However, once you start using it you'll soon realize that you just wasted your time installing it.

You can even configure IntelliJ to use it.

The only value that IntelliJ, LiteIDE, CGDB, etc. seem to provide is that you can more quickly ascertain that GDB debugging support for Go is extremely poor.

You can use it to step through some Go code, but try to print the value of anything other than very simple variable values and you'll be wasting your time wishing for a decent debugger.

Here's an example of what happens when you try to print the value of a map[string]string data structure using CGDB:

(gdb) print params
$1 = (github.com/go-martini/martini.Params) 0x15582 <runtime.reentersyscall+450>

...which is completely useless.

Next, try this:

(gdb) print params["UserID"]

...and you'll get "Bus error".

Delve (https://github.com/derekparker/delve) looks promising, since it is written in Go, but you drive it using the console, not via an IDE.

I would gladly pay for the enterprise version of IntelliJ (or any other IDE) that did a decent job supporting interactive debugging in Go.

As of now, fmt.Printf("%v", variable) is about as good as it gets.

Solution 5 - Debugging

I am happily using CGDB, a little curses wrapper around GDB.

Solution 6 - Debugging

EDIT

> The GO debugger is now a simple plugin in IntelliJ or PyCharm, no need > to install anything else. Just look for the Go plugin in the plugin > preferences.

Original answer (Nov 2015)

for those looking for the latest as of end of Nov 2015:

get delve

https://github.com/derekparker/delve

and follow the build / setup instructions:

https://github.com/derekparker/delve/wiki/Building

Get the latest IntelliJ (15) or PyCharm (5)

https://www.jetbrains.com/idea/download/

and get the go-lang-plugin in the IDE of your choice:

Pycharm -> Preference -> plugins -> search for go
current version is Version: 0.10.749
IntelliJ -> Preference -> plugins -> search for go
current version is Version: 0.10.749
  1. Setup a new Go project, or Import a project.
  2. Setup you Go SDK as prompted
  3. Setup your Go library (usually in GOROOT/src
  4. Setup a Run Application configuration top right corner by the 'play' icon:
  5. Edit Configurations -> click + -> Go Application

Define you package or file to run.

Once done with the setup, the Play icon and Debug icon should now be active, and you can set breakpoint, watches etc... as usual.

Cheers

Solution 7 - Debugging

  1. Option one - GDB https://golang.org/doc/gdb

  2. Delve

  3. Visual Studio Code with its go plugin (still uses delve).

I personally use option 3. For it you will need to have delve installed.

This video shows the debugging in action: https://youtu.be/uBjoTxosSys?t=16m11s (the entire video is very interesting).

Solution 8 - Debugging

IDE DEBUG ON GO IS POSSIBLE (AGAIN), ACTUALLY WORKS!

Delve works rather well on Mac OS X and is supported by IntelliJ IDEA Go Lang plugin.

I tested that on Mac OSX, IntelliJ Idea 14, Go 1.5.1, Delve 0.5

I had to run thru the usual loops of creating a self-signed cert, adding it to the system ring, etc (required in order to run a debugger in Mac OS X). At the end, I set a GO project inside IntelliJ and was repaid in regaining the usual IDE+debugger features: setting breakpoints, inspecting variables, single stepping.

That's way better than printing out values in order to debug code.

Solution 9 - Debugging

I've been pretty happy with Gogland (https://www.jetbrains.com/go/) which is basically Intellij with Go support. It's got a working Debugger that keeps getting better as they've been developing this. I've been using it since Jan 2017 and it's been mostly stable for me on a 2016 MBP.

> Goland is the codename for a new commercial IDE by JetBrains aimed at > providing an ergonomic environment for Go development.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniel WilliamsView Question on Stackoverflow
Solution 1 - DebuggingBenjamin GruenbaumView Answer on Stackoverflow
Solution 2 - DebuggingmetakeuleView Answer on Stackoverflow
Solution 3 - DebuggingVonCView Answer on Stackoverflow
Solution 4 - Debuggingl3xView Answer on Stackoverflow
Solution 5 - DebuggingpjvdsView Answer on Stackoverflow
Solution 6 - DebuggingMrEView Answer on Stackoverflow
Solution 7 - DebuggingPavel NikolovView Answer on Stackoverflow
Solution 8 - DebuggingMichele Giuseppe FaddaView Answer on Stackoverflow
Solution 9 - DebuggingmyykView Answer on Stackoverflow