"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

How to debug Rust in Helix?


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:

lldb-vscode - string variables memory addresses

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:

 2name = "rust"
 5command = "codelldb"
 6name = "codelldb"
 7port-arg = "--port {}"
 8transport = "tcp"
11name = "binary"
12request = "launch"
15completion = "filename"
16name = "binary"
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);

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:

After a few seconds, you’ll see the actual value of string variables:

codelldb - string variables values

Tags: helix dap lldb-vscode codelldb

Edit on GitHub

Related Posts: