GDB quick reference
This is a focused reference for the commands used most often while analyzing a local challenge binary. For context-rich stack and register views, see the pwndbg guide.
For a compact lookup with syntax, an example, and when to use each command, open the GDB and pwndbg command glossary.
Start a session
Section titled “Start a session”gdb -q ./challset disassembly-flavor intelset pagination offshow architecturestart # stop at main when symbols are availablestarti # stop at the first instructionrun # start or restart the programrun < input.txt # read stdin from a file| Command | What it does |
|---|---|
gdb -q ./chall |
Opens chall in GDB; -q suppresses the startup banner. |
set disassembly-flavor intel |
Displays x86 instructions in Intel operand order. |
set pagination off |
Prevents long output from pausing at a “press return” prompt. |
show architecture |
Prints the architecture GDB selected for the target. |
start |
Starts the program and stops at main when GDB can find it. |
starti |
Starts and stops at the first instruction, useful without symbols. |
run / r |
Starts or restarts the program with the current arguments. |
run < input.txt |
Runs the program with stdin read from a file. |
GDB commands can often be abbreviated while unambiguous. help COMMAND shows a command’s built-in usage; apropos WORD searches command names and descriptions.
Breakpoints and execution
Section titled “Breakpoints and execution”break main # function namebreak *0x401234 # address (use a runtime address for PIE)break *main+42 # offset from a known symbolinfo breakpointsdisable 1enable 1delete 1continue # c: run to the next stopnext # n: step over source-level callstep # s: step into source-level callnexti # ni: execute one instruction, stepping over callsstepi # si: execute one instruction, stepping into callsfinish # run until the current function returnsuntil # run until a later source linekill| Command | What it does |
|---|---|
break LOCATION / b |
Stops before a source line, function, or address. break *ADDRESS uses an instruction address. |
break *main+42 |
Sets a breakpoint 42 bytes from main’s entry. |
tbreak LOCATION |
Sets a temporary breakpoint that removes itself after it hits once. |
info breakpoints |
Lists breakpoints and their numbers, locations, and enabled state. |
disable N / enable N |
Turns breakpoint N off or back on without deleting it. |
delete N |
Removes breakpoint N. |
continue / c |
Resumes execution until the next breakpoint, signal, or exit. |
next / n |
Executes one source line, running over function calls. |
step / s |
Executes one source line and enters a called function when possible. |
nexti / ni |
Executes one machine instruction; a call runs through to its return site. |
stepi / si |
Executes one machine instruction and enters a call target. |
finish |
Runs until the current function returns to its caller. |
until |
Runs until a later source line in the current frame. |
kill |
Stops the current inferior (debugged process) without exiting GDB. |
ni is useful for a single machine instruction without following a call. si enters the call target. If debug symbols or source lines are missing, use the instruction-level commands.
Inspect values and registers
Section titled “Inspect values and registers”print variableprint/x variable # hexadecimalprint/d $rax # decimalprint *(long *)($rbp-8) # interpret an address as a valueinfo localsinfo argsinfo registersprint $rip| Command | What it does |
|---|---|
print EXPR / p EXPR |
Evaluates an expression and prints its value. |
print/x EXPR |
Prints the value in hexadecimal; /d requests signed decimal. |
info locals |
Lists local variables available in the selected stack frame. |
info args |
Lists arguments available in the selected stack frame. |
info registers |
Prints the current register values. |
print $rip |
Evaluates the register expression; prefix register names with $. |
*(long *)ADDRESS |
Casts an address to a pointer and reads a machine-sized value there. |
GDB expressions use C-like syntax and support casts. For a value located at a raw address, x is often quicker than a cast. Without debug symbols, source variable names such as variable may not exist.
Read memory with x
Section titled “Read memory with x”The general form is x/nfu ADDRESS: repeat count, format, unit size, and address. Leave out parts when GDB can infer them.
x/24gx $rsp # 24 giant words (8 bytes), hexadecimalx/64bx $rsp # 64 bytes, hexadecimalx/16wx $rsp # 16 words (4 bytes), hexadecimalx/s $rdi # NUL-terminated string at RDIx/i $rip # one instructionx/12i $rip # 12 instructions| Example | What it displays |
|---|---|
x/24gx $rsp |
24 values, hexadecimal format, 8-byte units, starting at the stack pointer. |
x/64bx $rsp |
64 individual bytes in hex. |
x/16wx $rsp |
16 four-byte values in hex. |
x/s $rdi |
A NUL-terminated string starting at the address in RDI. |
x/i $rip |
The instruction at the current instruction pointer. |
x/12i $rip |
12 instructions starting at the current instruction pointer. |
Formats include x hex, d signed decimal, u unsigned decimal, c character, s string, and i instruction. Units include b byte, h halfword (2 bytes), w word (4 bytes), and g giant word (8 bytes). Repeat the command after stepping; old output is a snapshot, not a live view.
Disassembly and call stack
Section titled “Disassembly and call stack”disassemble maindisassemble /r main # include instruction bytesdisassemble $rip, $rip+64bt # backtraceframe 1info frameinfo proc mappings| Command | What it does |
|---|---|
disassemble main |
Shows instructions in the main function. |
disassemble /r main |
Shows the same instructions with their encoded bytes. |
disassemble START, END |
Disassembles the address range from START to END. |
bt / backtrace |
Lists active function calls, starting with the current frame. |
frame N |
Selects frame N so locals and arguments can be inspected there. |
info frame |
Prints details about the selected stack frame. |
info proc mappings |
Lists the process’s mapped address ranges and permissions on supported systems. |
If the binary is stripped, use a known address and function boundaries found in Ghidra or pwndbg. For PIE, resolve the base in the live process before setting absolute breakpoints.
Useful habits
Section titled “Useful habits”- Use
set disassembly-flavor intelif Intel syntax is more readable to you. - Stop on a crash and inspect
info registers,x/24gx $rsp, andx/12i $ripbefore restarting. display/i $riprepeats an instruction view after each stop; remove it withundisplay.undisplay Nstops the automatic display numbered N;info displaylists active displays.gdb -x commands.gdb ./challruns the commands in the file as GDB starts, which is useful for repeatable breakpoints and settings.
Official reference
Section titled “Official reference”The GDB manual documents breakpoints, memory examination, and machine-code disassembly.