How to debug Rust in Helix?
2023-08-10
Categories: Development Environment
Helix supports debugging Rust by default using lldb-vscode. However, there is an issue where string variables are displayed as memory addresses instead of their actual values:
Noticing that CodeLLDB natively supports visualization of most common Rust data types, I would like to give it a try.
Here’s the step-by-step process:
Download the CodeLLDB extension:
1$ cd ~/Downloads/ 2$ wget https://github.com/vadimcn/codelldb/releases/download/v1.9.2/codelldb-aarch64-darwin.vsix
Setup the extension:
1$ mkdir -p ~/.local 2$ set fish_user_paths /Users/quantong/.local/extension/adapter $fish_user_paths 3$ codelldb
If you encountered this error:
1$ codelldb 2Error: "\"dlopen(/Users/quantong/.local/extension/lldb/lib/liblldb.dylib, 0x0009): 3tried: \\'/Users/quantong/.local/extension/lldb/lib/liblldb.dylib\\' (code signature in <71492E0A-B915-3776-BCB8-266C07A85228> 4\\'/Users/quantong/.local/extension/lldb/lib/liblldb.dylib\\' not valid for use in process: library load disallowed by system policy)\""
Remove attributes using xattr
:
1$ xattr -cr ~/.local/extension/
Retry launching:
1$ codelldb --port 13000
Switch to use codelldb
by adding the following to ~/.config/helix/languages.toml
:
1[[language]] 2name = "rust" 3 4[language.debugger] 5command = "codelldb" 6name = "codelldb" 7port-arg = "--port {}" 8transport = "tcp" 9 10[[language.debugger.templates]] 11name = "binary" 12request = "launch" 13 14[[language.debugger.templates.completion]] 15completion = "filename" 16name = "binary" 17 18[language.debugger.templates.args] 19program = "{0}" 20runInTerminal = false
1$ hx --health rust 2Configured language server: rust-analyzer 3Binary for language server: /opt/homebrew/bin/rust-analyzer 4Configured debug adapter: codelldb 5Binary for debug adapter: /Users/quantong/.local/extension/adapter/codelldb 6Highlight queries: ✓ 7Textobject queries: ✓ 8Indent queries: ✓
Create a new cargo package:
1$ cargo new hello_cargo
Open src/main.rs
and add the following code:
1fn main() { 2 let s = "world"; 3 let x = 2; 4 let b = true; 5 println!("Hello, {} {} {}!", s, x, b); 6}
Build your code by running:
1$ cargo build
The executable will be places in the target/debug
directory.
In the Helix editor, use the following steps for debugging:
- Press
<Space>
and theng
to go to Debug. - Press
b
to toggle breakpoint. - Press
l
to launch debug target. - Enther the binary path
target/debug/hello_cargo
and press Enter.
After a few seconds, you’ll see the actual value of string variables:
Tags: helix dap lldb-vscode codelldb
Related Posts:
- Turning Helix into an IDE with the help of WezTerm and CLI tools
- Debug Rust in Helix using lldb-vscode: display the contents of local string variables
- WezTerm: quickly select a command and open it in a new pane
- File tree workaround for Helix
- Open same file in already running instance of Helix