Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "identifier is undefined" or "not available" when inspecting a Rust variable in the VSCode debugger?

I've set up the Visual Studio Code debugger and run the following program.

pub fn main() {
    let mut chars = "test".chars();
    match chars.next() {
        Some(c) => {
            println!("What is the value of c, here?");
            if c == 'c' {
                println!("c");
            }
        }
        None => {}
    }
}

If I set a breakpoint at line 6, and look in the Variables and Watch panes, c does not evaluate, but rather passes the following message: identifier 'c' is undefined using cppvsdbg on Windows, or <not available> using lldb on Linux. I've confirmed that this happens both on Linux and Windows builds, for the current stable compiler version.

I've also added the following to Cargo.toml to no avail:

[profile.dev]
opt-level = 0
debug = true

For reference, here is my launch.json file, needed for the VS Code compiler:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/target/debug/test.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        }
    ]
}

Replace "(Windows) Launch" with your OS of choice.

Why is this the result? Is there a fix, or are there some compiler options that should be added?

like image 938
Christopher Ronning Avatar asked Sep 02 '25 05:09

Christopher Ronning


1 Answers

This issue is not reproducible with recent release of CodeLLDB.

CodeLLDB v1.7.0
rust : 1.60.0 (7737e0b5c 2022-04-04)
vscode: v1.67.0

Everything works as expected the debug view shows

iter: {end:0x000055555559105f}
c: 't'

Upgrading the codelldb to specified version will resolve the issue.

like image 118
Arjun Avatar answered Sep 04 '25 21:09

Arjun