Skip to content

GDB

31 commands

The GNU Debugger: set breakpoints, step through code, inspect memory and registers. Pair with GEF or pwndbg for exploit development.

  • debugging
  • exploit development
  • ELF

Install GDB

sudo apt install gdb

Starting5

gdb <binary>

Loads a program without running it.

Link
gdb -q --args <binary> <args>

Loads it with command-line arguments; -q skips the banner.

Link
gdb -p <pid>

Attaches to a running process.

Link
gdb <binary> <core>

Opens a core dump to see where a crash happened.

Link
gdb -batch -ex "<cmd>" <binary>

Runs commands non-interactively and exits.

Link

Running6

run

Starts the program (r). run < input.txt feeds a file to stdin.

start

Runs to the start of main and stops.

Link
continue

Resumes until the next breakpoint (c).

stepi

Executes one machine instruction, entering calls (si). nexti (ni) steps over calls.

step / next

Source-level stepping into or over function calls when debug symbols exist.

Link
finish

Runs until the current function returns.

Link

Breakpoints5

break <location>

Sets a breakpoint on a function, file:line or address (b *0x401136).

Link
break <function> if <condition>

Conditional breakpoint.

Link
watch <expr>

Stops when a memory location changes.

Link
info breakpoints

Lists breakpoints; delete <n> removes one.

Link
catch syscall <name>

Stops on a system call.

Link

Inspecting10

info registers

All general-purpose registers (i r). info registers rip for one.

x/<n><fmt> <addr>

Examines memory: n units in a format — x hex, s string, i instructions, g giant (8-byte) words.

Link
x/10i $rip

The next ten instructions.

Link
disassemble <function>

Disassembles a function.

Link
set disassembly-flavor intel

Intel syntax instead of AT&T; put it in ~/.gdbinit.

Link
backtrace

The call stack (bt).

Link
info proc mappings

The process memory map — find libc and stack base addresses.

Link
print <expr>

Evaluates an expression, such as the address of a libc function.

Link
set {int}<addr> = <value>

Writes to memory.

Link
set lt;reg> = <value>

Changes a register — for example to flip a check’s result.

Link

Exploit development (GEF / pwndbg)5

checksec

Shows NX, PIE, RELRO, canary and Fortify status of the binary.

Link
pattern create <n>

Generates a cyclic pattern to find the offset that overwrites the return address.

Link
pattern search $rsp

Finds the offset of the pattern in a register or memory after a crash.

Link
vmmap

Colour-coded memory map with permissions.

Link
telescope $rsp 20

Dereferences stack values recursively (pwndbg).

Link