Show Menu
Cheatography

Useful commands for GDB.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Command line

gdb [execu­table]
begin debugging of [execu­table]
gdb -p [PID]
attach to and debug [PID]
gdb -ex [comma­nds...]
execute [commands] on startup
gdb --args [execu­table] [argum­ent­s...]
begin debugging of [execu­table] with [argum­ents]

Breakp­oints

break, b [linenum]
set a breakpoint at [linenum]
break if [condi­tion]
set breakpoint here if [condi­tion] is met
break [code location] if [condi­tion]
set breakpoint at [code location] if [condi­tion] is met
info breakp­oints
list all breakp­oints and their numbers and location
clear
delete all breakp­oints
delete [break­point num]
delete [break­point num]
enable [break­point num]
enable [break­point num]
disable [break­point num]
disable [break­point num]
[code location] can be a number, for a line in the main file being debugged, or filena­me:­linenum, function, or filena­me:­fun­ction.

Executing

run
run the loaded program
run [args...]
run the loaded program with [args]
next
next line of source code
step
same a next but will dive into function calls
finish
continue until return instru­ction
continue
continue until next breakpoint
 

Examining Code

backtrace
show a backtrace
where
show the current call stack
print [variable]
print a repres­ent­ation of variable
display [variable]
same as print but will execute after each step instru­ction
print/­[fo­rmat] [variable]
print [variable] as [format]
displa­y/[­format] [variable]
display [variable] as [format]
Print and display can also show almost any C style expres­sion.

Format

a
pointer
c
character
d
signed int
u
unsigned int
f
floating point number
o
octal
x
hexade­cimal