Thoughts<Tech>

Debugging in Go

One of the features of Go that a developer may have friction with is — debugging. Debugging Go programs is not the most intuitive of experiences I have come across. I wanted to use this post to share some of my learnings of debugging a Go program.

I have primarily been a application developer and have built several projects with languages such as Java, JavaScript, C# and Ruby. I must confess that I have been pampered by various IDEs and editors providing rich interactive debugging experiences. I have only started learning Go a few days back.

When I encountered the scenario of debugging my program.I found out Go provides debugging support with GDB (GNU Project Debugger). GDB provides a command-line interface where the developer is presented with a prompt and commands should be executed to list source code, set breakpoints, pause or continue execution, evaluate & print variable values.

I found myself clueless. I had never used GDB. My debugging flow would involve the use of a GUI tool where I’d open my source file, scroll to the lines of interest, click in the editor’s gutter area alongside the lines to create breakpoints and run my program. The tool would pause the program at a breakpoint where I could mouse-hover variables to know their values. A watch window would allow me to add expressions that are evaluated as the program progresses giving me a sense of the state of the program. Now with GDB, I did not have any of those facilities.

My first response was denial, “It cant be so bad! Go is a popular language….how can it not have a debugger tool?!”. So I went about doing what most of my contemporaries would — Google it! Searching for answers led me to the following:

Of all the tools that I tried, I felt Delve provides a comprehensive range of features and it does not use any instrumentation to work. If you’re intrigued, I’d urge you to read Golang Debugging With Delve [Step by Step], which provides a good overview of how to setup Delve and debug a Go program.

There maybe many more debugging tools out there which I have not covered. With all that said, I still miss good GUI tools for debugging. I am a little apprehensive if Delve can scale when writing larger programs. It would also be great if the Go team can put together a good debugger system for the platform.

#blog #debug #debugging #go #golang #howto #posts #programming #tools