gdb cheatsheet


Getting addresses - use p

(gdb) p &buf1
$6 = (char (*)[64]) 0x404080 <buf1>

Examining memory - use x/[size][format][unit_size] start_addr.

(gdb) x/64 0x404040

source: Finding return address, break on function you want to return to e.g. br main. Then, run get the frame info with info frame.

Stack level 0, frame at 0x7fffffff95e0:
 rip = 0x4010a0 in main (loophole.c:51); saved rip = 0x7ffff7e26780
 source language c.
 Arglist at 0x7fffffff95d0, args: 
 Locals at 0x7fffffff95d0, Previous frame's sp is 0x7fffffff95e0
 Saved registers:
  rip at 0x7fffffff95d8


-g for debug symbols.


gcc -g -O0 -Wno-stack-protector -no-pie -z execstack loophole.c -o loophole