GDB

The GNU Debugger is a tool used for debugging another program while it executes. You may set breakpoints, examine memory and registers, and step through the code line by line or instruction by instruction.

This tool is most useful for reverse engineering an unknown executable or debugging a C program you are writing. GDB Enhancement Features is a popular addon specifically for reverse engineering and exploitation.

Commands

There are many commands, but here are some common ones. Note that most commands may be abbreviated.

CommandDescription
layoutSet the layout of the TUI: regs src
breakSet a breakpoint: main *0xaddress
runRun the program. Add arguments after run to use in ARGV
printPrint something: $rax 0x123
callCall a function in the program
xExamine memory: x $rsp
refreshRefresh the TUI
continueContinue running the program
nextRun the next line of the program, then stop
stepRun the next instruction of the program, going into a sub-routine if there is one
nextiRun the next instruction of the program
stepiRun the next instruction of the program, going into a sub-routine if there is one
commandsExecute commands when a breakpoint is reached
handleTell GDB how to handle signals (e.g. handle SIGABRT nostop)
inferiorsList child processes
python-interactiveStart an interactive python prompt

Most display commands accept a format for displaying the data as well. The FMT is specified like so: CMD/FMT ....

FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char), s(string)
  and z(hex, zero padded on the left).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).

Useful Commands

python
def onexit(event):
    gdb.execute("inferior 1") # switch to parent
    gdb.execute("continue")   # continue executing
gdb.events.exited.connect(onexit)
end