My experience on macOS trying to print values of Rust enum types from a debugger is that it's hopeless. Example:
#[derive(Debug)]
enum E {
A,
B,
}
#[derive(Debug)]
enum E2 {
A(usize),
B(usize),
}
fn main() {
let s = Some(5);
let s2 = Some("hi");
let s3 = Some(E::A);
let s4 = Some(E2::A(1));
println!("goodbye {:?} {:?} {:?} {:?}", s, s2, s3, s4);
}
When I run rustc a.rs -g
and then rust-lldb -- a
and set a breakpoint on line 18, I get this output:
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x000000010000462f a`a::main::h8bbda9164eb1d7fd at a.rs:18:5
15 let s2 = Some("hi");
16 let s3 = Some(E::A);
17 let s4 = Some(E2::A(1));
-> 18 println!("goodbye {:?} {:?} {:?} {:?}", s, s2, s3, s4);
19 }
Target 0: (a) stopped.
(lldb) p s
(core::option::Option<i32>) $0 =
(lldb) p s2
(core::option::Option<&str>) $1 =
(lldb) p s3
(core::option::Option<a::E>) $2 =
(lldb) p s4
(core::option::Option<a::E2>) $3 =
(lldb)
Is this everyone else's experience as well? Is there any hope for obtaining more useful output from the debugger here for enums in general? If not, is it possible to write pretty printers for some of the most common types?
I'm running this version, apparently:
lldb-1200.0.44.2
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)