LLDB cheatsheet

This cheatsheet serves as a quick reference for remembering most used commands in lldb.

Starting 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

Attaching to a running process

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

Breakpoints

Shortcuts

Full form command:

(lldb) breakpoint

Abbreviation for breakpoint command:

(lldb) br

Short form for breakpoint set command:

(lldb) b

Create breakpoints

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 breakpoints

List all your breakpoints:

(lldb) br l

Delete breakpoints

Delete a specific breakpoint:

(lldb) br delete breakpoint_number

Delete all breakpoints:

(lldb) br del

Running program

Start program

Start the program and stop at breakpoints:

(lldb) r

Step in (source code)

Move into the function called on the current line of source code:

(lldb) s

Step over (source code)

Execute the current line, skipping over function calls without stepping into them:

(lldb) n

Step in (Assembly)

Step into the function on the current assembly instruction:

(lldb) si

Step over (Assembly)

Step over the current assembly instruction without stepping into function calls:

(lldb) ni

Step out

Continue execution until the current function returns, then pause:

(lldb) f

Continue execution

Continue running the program until the next breakpoint or the end of the program:

(lldb) c

Examine memory

Memory content

Examine memory at a specific address:

(lldb) x address

Show 10 chunks of 4-byte memory in hexadecimal:

(lldb) x -s4 -fx -c10 address

Modify memory

Write a value to a specific memory address, e.g. write 0x42 at 0x1000:

(lldb) memory write 0x1000 0x42

Search memory

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

View function or variable addresses

Print the address of a specific function or variable:

(lldb) p &variable_name

Registers

Show the content of the registers:

(lldb) register read

Local variables

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

Disassembly

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!