Skip to content

Latest commit

 

History

History
184 lines (149 loc) · 2.88 KB

GDB Cheatsheet.md

File metadata and controls

184 lines (149 loc) · 2.88 KB

GDB Cheatsheet

This is a quick command reference for GDB (GNU Debugger).

load binary into GDB

gdb /path/to/binary

run binary inside GDB

(gdb) run <binary required arguments>

place breakpoint at main fucntion

(gdb) break main

check registers

(gdb) info registers

disassemble given register

(gdb) disassemble $<register name>

disassemble given function

(gdb) disassemble $<function name>

check registers including FPU, XMM, and MMX

(gdb) info all-registers

check the layout of process associated with binary running in GDB

(gdb) info proc mappings

disassemble using Intel syntax in GDB (default is AT&T)

(gdb) set disassembly-flavor intel

step into instruction

(gdb) stepi

examine memory for given address and print content as string

(gdb) x/s <memory address>

list function in binary such as main

(gdb) info functions

execute shell command from gdb

(gdb) shell <command here>

list global and static variables in binary

(gdb) info variables

examine first byte value of given variable

(gdb) x/xb &<variable name>

list source file (usually prints code in and around main function)

(gdb) list

list source file and start from given line number

(gdb) list <line number>

examine local variables of given function

(gdb) info scope <function name>

load symbol file in GDB

(gdb) symbol-file <filename>

list binary info and loaded sections

(gdb) info files

list breakpoints

(gdb) info breakpoints

disable breakpoint

(gdb) disable <breakpoint number>

enable breakpoint

(gdb) enable <breakpoint number>

delete breakpoint

(gdb) delete <breakpoint number>

examine memory for given address

(gdb) x/<repeat count, format, size> <address>

examine memory for given variable (used register for this example)

(gdb) x/<repeat count, format, size> $<register name>

continue execution after hitting breakpoint

(gdb) continue

change data at runtime

(gdb) set {<data type>} <address> = <value>

change register at runtime

(gdb) set $<register name> = <value>

change variable at runtime

(gdb) set <variable name> = <value>

get address of given function

(gdb) print <function name>

invoke function at runtime

(gdb) call <function name($args)>

set breakpoint at given address

(gdb) break *<address>

set conditional breakpoint that only applies when certian pre-set condition is met

(gdb) condition <breakpoint number> <variable> == <value>

set of commands to be executed every time execution halt

(gdb) define hook-stop
Type commands for definition of "hook-stop".
End with a line saying just "end".
><command 1>
><command 2>
><command 3>
>end
(gdb)