Is it a bug in Rust compiler or in LLVM?

Hi,

I'm trying to use VSCode for interactive debugging of a Rust code. When I debug a code like following I can see values of the x and y variables only in the first block but not in the second. Within the second block the x and y variables are still shown as Variable is optimized away and not available.

    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read line");
    let mut iter = input.split_whitespace();

    let mut desk = {
        let x: i32 = iter.next().unwrap().parse().unwrap();
        let y: i32 = iter.next().unwrap().parse().unwrap();
        knights::Desk::new(x, y)
    };

    let start;
    let res = {
        let x: i32 = iter.next().unwrap().parse().unwrap();
        let y: i32 = iter.next().unwrap().parse().unwrap();
        start = Instant::now();
        desk.find_first(x, y)
    };

The full code could be found in this topic:

First, do you debug a release or debug build?

Second, it's probably not exactly a bug in either. Compilers sometimes notice some variables are not needed (they can rewrite the code without them) and simply throw them away. Then you can't see their value. It's unfortunate, but it usually happens only in release (optimised) builds.

A debug build, so those variables should not be thrown away (optimized).

I don't know how to help, but I can relate: I'm also trying to debug Rust code in VSCode, and the variables window lists almost all variables as optimized away at all times. Surely that can't be right even if I'm not running the debug build I think I am.

Is anything being done to improve this?

What debugger are you using? In my own experience with debugging in VSCode, LLDB did a much better job of showing me proper values of things than GDB.

you can use cargo build at the terminal at first, then use vscode for interactive debugging for Rust code. such Variable is optimized away and not available will not shown.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.