Does any golang interactive debugger exist? [closed]

Solution 1:

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:

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:

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:

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:

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

  • Official page: cgdb - the curses debugger
  • Video: Easier Go debugging on the command line with CGDB