GDB (gef)

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

Commands

Cheatsheet link

1. Run the program

  • run, r

2. Breakpoints

2.1 Set breakpoint on the main function

2.2 Start command

a. start: sets a temporary breakpoint on the main procedure and starts executing the program (run command)

  • The main procedure is usually main (C/C++), but may vary with other languages

The start command does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then invoking the run command

b. starti: set a temporary breakpoint at the first instruction of the program execution and starts executing the program (run command)

2.3 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.4 Example on a specific instruction

  • Eg. hello world function

  • Set breakpoint on the call to puts

2.5 Other commands

2.6 If Position-Independent Executable (PIE) is used

  • If PIE is present, the memory addresses of the code shown by the disassembler will not match the one actually used during runtime

  • To deal with this, we can simply run the binary first, and disassemble again, to view the runtime memory addresses

3. Memory

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

  • f: Format character (default x)

    • x: hexadecimal (default)

    • d:decimal

    • o: octal

    • u: unsigned decimal

    • t: binary

    • f: floating point

    • a: address

    • c: char

    • s: string

    • i: instruction

  • u: Unit (default w)

    • b: byte

    • h: halfword (16 bit, 2 bytes)

    • w: word (32 bit, 4 bytes) (default)

    • g: giant word (64 bits, 8 bytes)

4. Printing

  • Print values with C-like syntax, and can function as:

    • Print registers

    • Type conversion

    • Calculator

    General syntax: print/f, p/f

Last updated