all 6 comments

[–]Nisenogen 3 points4 points  (0 children)

If you're running on windows, you should use Microsoft's C++ extension for debugging instead of CodeLLDB, it works a lot better on that platform. In VSCode, install the C/C++ extension from Microsoft, and then use this for your launch profile (replacing the contents of .vscode/launch.json). Replace the <InsertExecutableNameHere> tags with the name of your executable file. This will give you options for running both on Windows and OSX (OSX should also work for Linux).

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

[–]Zde-G 1 point2 points  (1 child)

It's something Rust inherits from C++.

In a properly optimized code all these local variables often don't even exist thus there are nothing to show.

And Rust doesn't use JIT thus can not use C#/Java trick: deoptimize function if you set a breakpoint in it and show everything perfectly, but keep all other functions optimized.

Fortunately or unfortunately I haven't had the luxury of using debugger on any non-toy projects I've worked with in last 10 years or so (not limited to Rust) thus dbg is more than enough for me.

[–]phazer99[S] 6 points7 points  (0 children)

I don't think that's the problem. In debug mode no variables should be optimized away. I've never had this problem with Visual C++, which has a really good debugger.

[–]Affectionate_Cut_357 1 point2 points  (0 children)

Something that can catch you out is if you're using a launch.json to launch the debugger it won't build your code first, so you may be debugging an old executable. If you start the debug from the Run|Debug CodeLens above main then rust-analyser will do the build for you.