Go has a debugger—and it’s awesome!
Something that often, uh... bugs1 Go developers is the lack of a proper debugger. Sure, builds are ridiculously fast and easy, and println(hex.Dump(b))
is your friend, but sometimes it would be nice to just set a breakpoint and step through that endless if
chain or print a bunch of values without recompiling ten times.
CC BY 2.0 image by Carl Milner
You could try to use some dirty gdb hacks that will work if you built your binary with a certain linker and ran it on some architectures when the moon was in a waxing crescent phase, but let's be honest, it isn't an enjoyable experience.
Well, worry no more! godebug is here!
godebug is an awesome cross-platform debugger created by the Mailgun team. You can read their introduction for some under-the-hood details, but 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 Continue reading