This cheatsheet serves as a quick reference for remembering most used commands in lldb.
You can start debugging by directly running a program
from the command line:
lldb program
If you have command line arguments, e.g. if you want to debug
program -f arg1 arg2
:
lldb -- program -f arg1 arg2
Alternatively, you can start the debugger and then add your program
later:
lldb
(lldb) file /path/to/program
Attach to a running process using its PID (e.g., PID = 96389):
(lldb) attach -p 96389
Attach to a running process using its name (e.g., name = program):
(lldb) attach -n program
Full form command:
(lldb) breakpoint
Abbreviation for breakpoint
command:
(lldb) br
Short form for breakpoint set
command:
(lldb) b
Note: For breakpoints to be set on line numbers, compile with debugging symbols.
To set a breakpoint at a specific line in a file:
(lldb) br set -f file_name -l line_number
(lldb) b file_name:line_number
To set a breakpoint at a specific function:
(lldb) b function_name
Or target a function in a specific file:
(lldb) b file_name:function_name
List all your breakpoints:
(lldb) br l
Delete a specific breakpoint:
(lldb) br delete breakpoint_number
Delete all breakpoints:
(lldb) br del
Start the program and stop at breakpoints:
(lldb) r
Move into the function called on the current line of source code:
(lldb) s
Execute the current line, skipping over function calls without stepping into them:
(lldb) n
Step into the function on the current assembly instruction:
(lldb) si
Step over the current assembly instruction without stepping into function calls:
(lldb) ni
Continue execution until the current function returns, then pause:
(lldb) f
Continue running the program until the next breakpoint or the end of the program:
(lldb) c
Examine memory at a specific address:
(lldb) x address
Show 10 chunks of 4-byte memory in hexadecimal:
(lldb) x -s4 -fx -c10 address
Write a value to a specific memory address, e.g. write 0x42
at 0x1000
:
(lldb) memory write 0x1000 0x42
Search for a value in a memory range, e.g. search for 0x12345678
between
0x1000
and 0x2000
:
(lldb) memory find -s4 -e 0x1000 0x2000 0x12345678
Print the address of a specific function or variable:
(lldb) p &variable_name
Show the content of the registers:
(lldb) register read
Show all local variables:
(lldb) frame variable
(lldb) fr v
Show specific variable, e.g. foo
:
(lldb) fr v foo
Print value of specific variable, e.g. foo
:
(lldb) p foo
Show assembly for a specific function, e.g. main
:
(lldb) di -n main
Find this post helpful? Subscribe and get notified when I post something new!