Below is a curated list of essential LLDB commands I regularly use for debugging. These cover the basics you’ll need day-to-day. For a more complete overview, check out this excellent cheat sheet (direct PDF link).
Compilation #
To enable debugging info during compilation, use the following flags:
-g -ggdb
Launching and Running #
Start LLDB with your executable:
$ lldb Executable
(lldb) target create "Executable"
(lldb) run [args] # Optional arguments
Navigating the Stack #
Breakpoints #
Set breakpoints to pause execution:
b main # Short form
breakpoint set --name main # Full form
Backtraces #
View call stack information:
bt # Short form
thread backtrace # Full form
thread backtrace all # For all threads
Frame Information & Navigation #
frame info # Show info about current frame
down # Move down the stack
frame s -r-1 # Move down (relative)
frame select --relative=-1 # Same
up # Move up the stack
frame s -r1
frame select --relative=1
f 3 # Select specific frame
fr s 3
frame select 3
Program Execution Control #
Action | Short Form | Long Form |
---|---|---|
Continue | c |
thread continue |
Step in | s |
step / thread step-in |
Step over | n |
next / thread step-over |
Step out | — | finish / thread step-out |
Evaluating and Inspecting Variables #
Local Variables #
frame variable # Lists all local variables
fr v # Short form
Specific Variable #
p var # Print value of 'var'
fr v var
frame variable var
Evaluate Expressions #
expr var + 1 # Evaluate expression
Memory Inspection (Advanced) #
memory read --format x --size 4 --count 4 0xADDRESS
Workflow Tips #
-
Use a
.lldbinit
file to automate breakpoint setting or create command aliases. -
Shorten repetitive commands using
command alias
, e.g.:command alias bp breakpoint set --name