Setting up gdb for convenient debugging

The debugger gdb is a wonderful tool for writing working software, and also for reverse engineering. There are a few configuration details that can make it more convenient, and there’s almost no limit to how you could reconfigure or extend it if that’s an interesting rabbit hole for you.

The first thing I do to configure gdb is turn off the verbose license notice. I appreciate the history behind this stridence, but I don’t want to read it every time. Until recently, there was a command-line option (-q) to suppress it but no way to save it in a configuration file because the notice is printed before any normal configuration file is even read. Since version 11, there is a new, early configuration file that can control this option.

Using your text editor, create a file in your home directory named .gdbearlyinit and put the following line in it.

set startup-quietly on

That’s all! On unix, a file with a name starting with . is considered hidden, and for example ls will normally not show such files. Programs will often read hidden configuration files in your working directory or home directory to let you use your text editor to set various options.

The regular configuration file for gdb is named .gdbinit and also goes in your home directory. Since in this class we use Intel assembly syntax but the default for gdb is AT&T syntax, we can put the following line in .gdbinit to set the desired syntax once and for all.

set disassembly-flavor intel

You don’t need to worry about any other configuration details for this class, but feel free to dabble if you’re interested. For instance, I prefer to see structures pretty-printed rather than crammed onto one line, so I have the following line in my .gdbinit.

set print pretty on

Lastly, bookmark the gdb documentation, which is a treasure trove. Most of the same information is available live from within gdb if you run the help command at the (gdb) prompt.

You have attempted of activities on this page