Skip to main content

Debugging Rust with LLDB

What is LLDB?

A low-level debugger similar to GDB. macOS uses LLDB instead of GDB by default. The Rust wrapper rust-lldb provides better output for Rust types.

Running it

# Rust-specific wrapper (improved type output)
rust-lldb ./target/debug/my_program

# Or use lldb directly
lldb ./target/debug/my_program

Key commands

CommandDescription
b main.rs:10Set a breakpoint at line 10 of main.rs
b 10Set a breakpoint at line 10 of the current file
rRun the program
cContinue execution to the next breakpoint
nExecute the next line (next, without entering a function)
sExecute the next line (step, entering a function)
btPrint the call stack (backtrace)
p <variable>Print a variable's value
qExit the debugger (quit)

Printing variables (frame variable)

frame variable # Print all local variables in the current scope
frame variable self # Print self
frame variable self.name # Print the self.name field
frame variable --show-globals # Include global variables
frame variable --show-types # Include type information
frame variable --show-types --show-values # Print types + values

Evaluating expressions

expr <expression> # Evaluate and execute an expression in the current context

Using GDB (Linux)

rust-gdb ./target/debug/my_program

GDB commands are nearly identical to LLDB commands, but there are some differences:

  • info locals → local variables (LLDB's frame variable)
  • info breakpoints → list of breakpoints
  • delete <number> → delete a breakpoint