How do I debug a Go program? I have been using the Gedit Go IDE, but it doesn\'t have debugging. Is there a way to step though my code and inspect memory? Or am I stuck with
New initiative (started May 2014): derekparker/delve
Delve is a Go debugger, written in Go.
(mainly for Linux though, OsX support is coming, Windows supportunknownsupported in 2016)
- Attach to an already running process
- Launch a process and begin debug session
- Set breakpoints, single step, step over functions, print variable contents
The debugger can be launched in three ways:
Compile, run, and attach in one step:
$ dlv -run
Provide the name of the program you want to debug, and the debugger will launch it for you.
$ dlv -proc path/to/program
Provide the pid of a currently running process, and the debugger will attach and begin the session.
$ sudo dlv -pid 44839
Delve can insert breakpoints via the breakpoint command once inside a debug session, however for ease of debugging, you can also call
runtime.Breakpoint()
and Delve will handle the breakpoint and stop the program at the next source line.