Sunday, February 26, 2012

CGDB: My New Favorite Debugger

I have just recently begun delving in the use of debuggers. For some odd reason my previous professors never encouraged their use or mentioned their existence. As I have started to move into more projects involving C and, in Object-Oriented Programming, C++, the C/C++ debuggers available have proved to be a godsend in finding and correcting bugs. First I began with standard gdb, which is nice, but I really yearned for something that integrated a little better with the source code and had more readability. Then I found out about the -tui flag for gdb. This opens a nice window for the source code and creates a nice gui in the terminal for gdb. Stepping into certain functions pulls up the source for that function regardless of what file it is in, and setting breakpoints does not require me to have the file open in another pane or tab in order to figure out the correct line number. After that, I thought gdb -tui was all I would ever need, and I would never go back to using standard gdb. Many people would argue that ddd is much better, but given that it uses X windows, I would much rather use a terminal debugger and keep my hands off the mouse. The graphical front end is nice, but it involves too much clicking, and the font ddd uses is horrendous.

Then I found something amazing: cgdb, the curses debugger. Given that I am a die-hard vi user, this nifty debugger is one of the coolest tools I have found for debugging C and C++ code. The front page of the cgdb website, which I have linked above, shows a few of the features:


Features

  • Syntax-highlighted source window
  • Visual breakpoint setting
  • Keyboard shortcuts for common functions
  • Searching source window (using regexp)
  • Scrollable gdb history of entire session
  • Tab completion
  • Key mappings (macros)
It follows the same general escape and insert modes that vi uses, has syntax-highlighting, which neither ddd or gdb -tui have, and allows for regex searching through the source code. With cgdb I can still work in the terminal and continue to maintain the vi-oriented mindset I have become so accustomed to. I doubt I will ever come across another debugger as clean and readable as cgdb. It has earned its spot in my toolset, and although it is just an ncurses frontend to gdb, it is very well thought out and made a great tool even better. 

2 comments: