Recently I have been curious about exploring golang. I want to carry over some of the habits I've developed in Python. So I got curious to know what the debugging experience is like for golang. I haven't really worked with debugging a compiled language before.
Go's official docs have a page dedicated to debugging with gdb. But they basically give a pretty loud disclaimer that you should not use it unless you really have to. Luckily they give a recommendation for a debugger that you can use called "delve".
The installation instructions are pretty straightforward assuming you've got some experience with the basics of using go. I was pleasantly surprised by how easy it was to get up and running with delve, in conjunction with a pretty common structure for code.
Exercism is great because it gives you a module and test module no matter what language you're using. This is often not too far off from how I actually develop. Running the tests for exercism is done with this automagic command (assuming your in your exercism exercise directory):
$ ~/go/bin/dlv test
Type 'help' for list of commands.
(dlv)
You're now dropped into a dlv
prompt. help
shows you a bunch of commands.
You can set a breakpoint or few by saying b
followed by the name of the
function you want to break on. You've got tools for looking at local variables,
and evaluating code. You can use c
to continue as with pdb and n
to
evaluate only to the next line of code.
One area that will take getting used to is the funcs
command to search for
the function that you want to set a breakpoint at. It works like a filter and
it lets you find which function you want to break on with the b
command.
Another interesting command is rebuild
. You can make changes to your source
code or tests, and rebuild within the dlv
prompt. And then you can
effectively re-run all your tests, with updated source code.
This seems like a fantastic tool and I look forward to exploring it some more:
Addendum: