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
startcommand does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then invoking theruncommand
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
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 (default1)f: Format character (defaultx)x: hexadecimal (default)d:decimalo: octalu: unsigned decimalt: binaryf: floating pointa: addressc: chars: stringi: instruction
u: Unit (default w)b: byteh: 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