Skip to content

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.

Terminal window
gdb -q ./chall
set disassembly-flavor intel
set pagination off
show architecture
start # stop at main when symbols are available
starti # stop at the first instruction
run # start or restart the program
run < 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.

break main # function name
break *0x401234 # address (use a runtime address for PIE)
break *main+42 # offset from a known symbol
info breakpoints
disable 1
enable 1
delete 1
continue # c: run to the next stop
next # n: step over source-level call
step # s: step into source-level call
nexti # ni: execute one instruction, stepping over calls
stepi # si: execute one instruction, stepping into calls
finish # run until the current function returns
until # run until a later source line
kill
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.

print variable
print/x variable # hexadecimal
print/d $rax # decimal
print *(long *)($rbp-8) # interpret an address as a value
info locals
info args
info registers
print $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.

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), hexadecimal
x/64bx $rsp # 64 bytes, hexadecimal
x/16wx $rsp # 16 words (4 bytes), hexadecimal
x/s $rdi # NUL-terminated string at RDI
x/i $rip # one instruction
x/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.

disassemble main
disassemble /r main # include instruction bytes
disassemble $rip, $rip+64
bt # backtrace
frame 1
info frame
info 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.

  • Use set disassembly-flavor intel if Intel syntax is more readable to you.
  • Stop on a crash and inspect info registers, x/24gx $rsp, and x/12i $rip before restarting.
  • display/i $rip repeats an instruction view after each stop; remove it with undisplay.
  • undisplay N stops the automatic display numbered N; info display lists active displays.
  • gdb -x commands.gdb ./chall runs the commands in the file as GDB starts, which is useful for repeatable breakpoints and settings.

The GDB manual documents breakpoints, memory examination, and machine-code disassembly.