Home > other >  cannot inspect "if let" variables in gdb
cannot inspect "if let" variables in gdb

Time:09-13

I'm having trouble inspecting variables set by if-let statements, for instance the following main.rs in a freshly created cargo project named "iflet-rust":

#[derive(Debug)]
struct Stuff;
fn maybe() -> Option<Stuff> {
    Some(Stuff {})
}
fn main() {
    if let Some(first) = maybe() {
        println!("first {:?}", first); // line 8, cannot inspect 'first' here
    }

    let maybe_stuff = maybe();
    if maybe_stuff.is_some() {
        let second = maybe_stuff.unwrap();
        println!("second {:?}", second); // no problem here
    }
}

Then running cargo build and rust-gdb target/debug/iflet-rust

Reading symbols from target/debug/iflet-rust...
(gdb) b main.rs:8
Breakpoint 1 at 0x83f1: file src/main.rs, line 8.
(gdb) b main.rs:14
Breakpoint 2 at 0x848b: file src/main.rs, line 14.
(gdb) r
Starting program: iflet-rust/target/debug/iflet-rust 

Breakpoint 1, iflet_rust::main () at src/main.rs:8
8               println!("first {:?}", first); // cannot inspect 'first' here
(gdb) p first
No symbol 'first' in current context
(gdb) info locals
No locals.
(gdb) c
Continuing.
first Stuff

Breakpoint 2, iflet_rust::main () at src/main.rs:14
14              println!("second {:?}", second); // no problem here
(gdb) info locals
second = iflet_rust::Stuff
maybe_stuff = core::option::Option::Some

Is this a know limitation or am I missing something?

CodePudding user response:

It was an issue in the compiler, updating to Rust from 1.60 to 1.63 fixes the problem.

I shouldn't have limited my search to open issues, unfortunate timing.

See https://github.com/rust-lang/rust/issues/97799

  • Related