I don't know if it will fix this specific issue, but at the very least you probably want to use the rust-lldb wrapper that ships with rust rather than plain lldb. This adds a bunch of pretty printers for rust types.
Thanks for the suggestion. The following works for me for small vectors (which is the cases for many of my tests):
rust-lldb target/debug/cargo_test -Q
b main.rs
run
p v
Here is the output that I get:
rust-lldb target/debug/cargo_test -Q
Current executable set to '/Users/bradbell/trash/rust/cargo_test/target/debug/cargo_test' (arm64).
(lldb) b main.rs:4
Breakpoint 1: where = cargo_test`cargo_test::main::h2670d8b4fb84495b + 148 at main.rs:4:4, address = 0x00000001000014a8
(lldb) run
Process 19485 launched: '/Users/bradbell/trash/rust/cargo_test/target/debug/cargo_test' (arm64)
Process 19485 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x00000001000014a8 cargo_test`cargo_test::main::h2670d8b4fb84495b at main.rs:4:4
1
2 fn main() {
3 let v : Vec<u32> = vec![1, 2, 3];
-> 4 println!( "{:?}", v);
5 }
6
Target 0: (cargo_test) stopped.
(lldb) p v
(alloc::vec::Vec<unsigned int, alloc::alloc::Global>) size=3 {
[0] = 1
[1] = 2
[2] = 3
}
(lldb)
Here are some of my attempts to access a single element of v:
(lldb) p v[0]
˄
╰─ error: type 'alloc::vec::Vec<unsigned int, alloc::alloc::Global>' does not provide a subscript operator
(lldb) p v.buf.inner.ptr.pointer.pointer[0]
(unsigned char) '\x01'
We must be using different version of rust-lldb. It seems I'm not getting the pretty-printing of the slice as a whole, and instead I see its fields when I print it:
(lldb) p s
(&[u32]) $0 = {
data_ptr = 0x00005555555af940
length = 3
}
I'm using:
$ rust-lldb --version
lldb version 16.0.0
Looks like the latest version is 20.
Did you try just using p s[0]? Maybe in your version it will work.
It depends a lot on the custom implementation of LLDB. For what it's worth, the current version of RustRover with LLDB-19 (they recent upgrade) shows the values as expected with p v and the individual values with p v[0] on Windows; I don't know what version they currently have on macOS.
Sometimes, the GNU toolchain / gdb gets better results, at least in the IDE, but not always, and it's slower to compile code and launch tests in that environment, so I'm using it only when I need to see variables in the debugger.
It's often easier to simply print them out than to rely on a debugger.