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.

Start gdb quietly

When you run gdb interactively, it prints a lengthy copyright and license notice before the prompt. None of that text is related to debugging your program, and it is anithetical to the terse unix style. In addition to being distracting, it can scroll away recent terminal text related to why you are debugging a program.

So, while I appreciate the history behind this stridence, turn off the introduction. On a per-run basis, you can use the -q (quiet) option.

$ gdb -q
(gdb)

On older versions of gdb, the command-line option is the only way to start quietly. A shell alias such as gdb='gdb -q' can make using the option more convenient.

Since version 11.1, gdb has supported a setting to start up quietly. The message is normally printed before the initialization file is read, so this setting has to go in a special ‘early’ initialization file. Edit a file named .gdbearly-init in your home directory (you probably have to create it) and put the following line in it.

set startup-quietly on

If you do want to read the introductory message, you can print it at any time within gdb using its show version command.

Other configuration and help

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