First of all, you should be using GDB from within Emacs. Anything less is uncivilized. There's a menu item under "Tools" when you're editing C code that starts gdb. This will, for example, automatically whisk you to the relevant line of your source code in an Emacs buffer when you hit a breakpoint. My major annoyances with GDB include the inability to reasonably display data structures like arrays.
There's a program called DDD which helps with this, but I never fell in love with it. At least, not until I noticed its interface to Gnuplot. That looks pretty cool.
A simple way to help with this is to just define a new GDB command to print your data structure formatted in whatever way you want. Here's how you do it.
This technique is also handy for debugging parallel programs. As long as your bug doesn't require more than a few separate processes to manifest itself, this technique works: First use Norm Matloff's parallel debugging trick and put this
int gdb_parallel_debug=1;
while (gdb_parallel_debug) {
printf("Process %d waiting for gdb process to attach...\n", getpid());
fflush(stdout);
sleep(5);
}
in your code. Then put this in .gdbinit
define pattach attach $arg0 finish set gdb_parallel_debug=0 next next end
And ta-da! You can start gdb, then just type pattach 12345 and you'll automatically find yourself at the first statement after the above while loop.
