Debugging with GDB

More Information

GDB Documentation

GDB Initialization Settings

You'll want some stuff in your ~/.gdbinit file:

# Turn off display "paging".
set height 0

# Don't drop into debugger when SIGPIPE happens.
handle SIGPIPE nostop

# Display more stuff.
set print static-members off
set print vtbl on
set print object on
set print pretty on

# Be friendlier when debugging threads.
set scheduler-locking step

# Find some optional (unfound) source.
dir /home/ksedgwic/rpm/BUILD/ACE_wrappers/ace

Useful Commands

Attach to a running process:

# Start gdb on the same executable
gdb /usr/bin/myprog

# Attach to the already running process
(gdb) attach <pid>

Log to a file:

(gdb) set logging file FILE
(gdb) set logging on

Capture backtraces from all threads:

(gdb) thread apply all bt

Find the source code line number for an address:

(gdb) info line * 0x2530526

Pass ^C (SIGINT) to the program instead of trapping into the debugger:

(gdb) handle SIGINT pass nostop

Debugging allocation calls

Breaking on malloc, realloc and free will sometimes fail to find the correct routines due to some early weak bindings in the dynamic linker. Break on these entry points instead:

(gdb) b __libc_malloc
(gdb) b __libc_realloc
(gdb) b __libc_free

Using the Text User Interface

You can enable the Text User Interface (TUI) on the command line:

gdb -tui <cmd>

The TUI can also be entered from the prompt with "C-x C-a" (Control-x Control-a).

Once in the TUI you may prefer "single key mode" enabled with "C-x s".