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.
The Go extension allows you to launch or attach to Go programs for debugging. You can inspect variables and stacks, setting breakpoints, and do other debugging activities using VS Code's Debugging UI. These debugging features are possible by using Delve, the Go debugger.
To debug a program, execute the dlv debug command. Attach the filename at the end of this command, and debugging will start. For example, if you want to debug the main.go file, run the command dlv debug main.go . It is also known as “delve server” because this is a running process waiting for instructions.
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.
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.py
script coming with go 1.2 does not work for a GDB that was compiled with python3 support (current Ubuntu for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With