GDB-gef

GNU Debugger (GNU), with the gef wrapper to provide us with extended features.

Commands

Cheatsheet link

1. Run the program

  • run, r

gdb <binary>
gef> run

2. Breakpoints

2.1 Set breakpoint on the main function

gef> break main
gef> b main

2.2 Navigate through the program

a. nexti: go instruction by instruction through the program, without stepping into function calls

b. next: go through each line of code, without stepping into function calls

c. stepi: go instruction by instruction, while stepping into function calls

d. step: go through each line of code, while stepping into function calls

Summary table

Command
Navigate through?
Step into function calls (eg. puts())?

nexti

Instructions

NO

next

Line of code (may consist of multiple instructions)

NO

stepi

Instructions

YES

step

Line of code (may consist of multiple instructions)

YES

2.3 Example on a specific instruction

  • Eg. hello world function

gef> disassemble main # "disass" works too
Dump of assembler code for function main:
   xxx
   0x0804840f <+20>:	push   0x80484b0
   0x08048414 <+25>:	call   0x80482d0 <puts@plt>
   xxx
End of assembler dump.
  • Set breakpoint on the call to puts

gef> break *main+25
gef> break *0x08048414
gef> break *puts

2.4 Other commands

gef> info breakpoints
gef> delete <Num> # "del" or "d" works too

3. Memory

gef> x/nfu <addresss>
  • To print memory (refer to cheat sheet link above)

    • n: How many units to print (default 1)

    • f: Format character

    • u: Unit

gef> x/a <address> # print pointer address
gef> x/10c <address> # print 10 chars
gef> x/s <address> # print as C string

Last updated