← All posts

GDB cheatsheet

Running (or re-running) a program

r

Running a program that requires CLI arguments

 r [args]

Starting a program and breaking at its entry point

start 

Continuing execution of a program stopped at a breakpoint

c

Setting Code Breakpoints:

 break <function name>
 b <function name>
 b *<address>

Listing Code Breakpoints:

info breakpoints
info b

Unsetting Code Breakpoints:

clear *<address>
clear <function name>
delete <breakpoint number>

One-time Disassembly Display

disassemble <address or symbol name>

Continuously-updating Disassembly Display

display/10i <instruction pointer / program counter>

Break On Write-Only Access

watch <address>

Break On Read-Only Access

rwatch <address>

Break On Read-And-Write Access

awatch <address>

Setting the access-size of watchpoints

watch *(char *) <address> 
watch *(long long *) <address>

Disabling Breakpoints

disable <breakpoint number>

Enabling Breakpoints

enable <breakpoint number>

Hardware Breakpoints

hb *<address>
hb <function name>

Viewing Registers

info registers
info r rax
info r rax rbx rsp
p/x $rax

Modifying Registers

set $rax = 0xdeadbeeff00dface

Viewing Memory

x/8xb $rsp # display the content of 8 consecutive bytes of memory
x/4xh $rsp # display the content of 4 consecutive halfwords (2 bytes each) of memory 
x/2xw $rsp # display the content of 2 consecutive words (4 bytes each) of memory 
x/1xg $rsp # display the content of 1 memory unit (the size determined by the architecture) 

Modifying Memory

set {char}$rsp = 0xFF
set {long long}$rsp = 0x1337bee7

Stack Backtrace

bt

Step Over

nexti
ni

Step Into

stepi
si

Step Out

finish
fin

Run Until Address

until <address>
u <address>

Attaching to running processes

attach <process ID>

Changing Disassembly Syntax

set disassembly-flavor intel
set disassembly-flavor att