Debugging Rust Applications in VSCode Using CodeLLDB
To debug Rust programs in VSCode, the CodeLLDB extension prvoides robust support. Follow this setup guide to configure your debugging environment.
Installing Required Components
- Open VSCode and navigate to the Extensions view (Ctrl+Shift+X)
- Search for and install the CodeLLDB extension
- Verify Rust installlation with:
rustc --version
- Install LLDB debugger:
- macOS:
brew install llvm - Linux:
sudo apt install lldb
- macOS:
Configuring Debug Settings
- Open your Rust project in VSCode
- Access the Debug view (Ctrl+Shift+D)
- Create a
launch.jsonfile with LLDB configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Rust Debug",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/target/debug/app_binary",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "cargo build",
"stopAtEntry": false
}
]
}
Debugging Workflow
- Set breakpoints by clicking the guter next to line numbers
- Start debugging with F5 or the debug toolbar
- Use debugging controls:
- Step Over (F10)
- Step Into (F11)
- Step Out (Shift+F11)
- Inspect variables in the Debug sidebar
Optional Automation
For automatic rebuilds during development:
- Install cargo-watch:
cargo install cargo-watch
- Add to
.vscode/tasks.json:
{
"label": "watch",
"type": "shell",
"command": "cargo watch -x run"
}