Contents

GDB Basics Cheatsheet

Launching

Launching against a binary

1
gdb ./path-to-binary

Launch against a process ID

1
gdb -silent `pidof <binary-name>`

Launch in TUI Mode

1
gdb -tui

Commands

Set breakpoint

1
2
(gdb) b main // Breaks at main()
(gdb) break strcpy // Breaks at strcpy()

List defined breakpoints

1
(gdb) info b

Continue execution

1
(gdb) c

Step into

1
(gdb) s

Show stored values

1
2
3
4
5
6
(gdb) print $esp

(gdb) x/5x $esp-10 // in Hex
(gdb) x/5s $esp-10 //String
(gdb) x/5d $esp-10 //Decimal
(gdb) x/5i $esp-10 //Assembly Instructions

Show where in the source file we are

1
(gdb) list

Show where execution is

1
(gdb) where

Show symbols

1
(gdb) info file

Show all defined functions

1
(gdb) info functions

Show function disassembly

1
(gdb) disas <func-name>

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
(gdb) disas strcpy
Dump of assembler code for function strcpy:
0x42079dd0 <strcpy+0>:  push   %ebp
0x42079dd1 <strcpy+1>:  mov    %esp,%ebp
0x42079dd3 <strcpy+3>:  push   %esi
0x42079dd4 <strcpy+4>:  mov    0x8(%ebp),%esi
0x42079dd7 <strcpy+7>:  mov    0xc(%ebp),%edx
0x42079dda <strcpy+10>: mov    %esi,%eax
0x42079ddc <strcpy+12>: sub    %edx,%eax
0x42079dde <strcpy+14>: lea    0xffffffff(%eax),%ecx
0x42079de1 <strcpy+17>: jmp    0x42079df0 <strcpy+32>
0x42079de3 <strcpy+19>: nop
0x42079de4 <strcpy+20>: nop
0x42079dfb <strcpy+43>: mov    %esi,%eax
0x42079dfd <strcpy+45>: pop    %esi
0x42079dfe <strcpy+46>: pop    %ebp
0x42079dff <strcpy+47>: ret
End of assembler dump.