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 -ggdbLaunching and Running#
Start LLDB with your executable:
$ lldb Executable
(lldb) target create "Executable"
(lldb) run [args] # Optional argumentsNavigating the Stack#
Breakpoints#
Set breakpoints to pause execution:
b main # Short form
breakpoint set --name main # Full formBacktraces#
View call stack information:
bt # Short form
thread backtrace # Full form
thread backtrace all # For all threadsFrame 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 3Program 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 formSpecific Variable#
p var # Print value of 'var'
fr v var
frame variable varEvaluate Expressions#
expr var + 1 # Evaluate expressionMemory Inspection (Advanced)#
memory read --format x --size 4 --count 4 0xADDRESSWorkflow Tips#
Use a
.lldbinitfile to automate breakpoint setting or create command aliases.Shorten repetitive commands using
command alias, e.g.:command alias bp breakpoint set --name
