19

I am trying to debug a Rust application using VSCode, but I am unable to inspect any local variables or use the watch window (see attached).

All breakpoints work fine, I just cannot view any variables, etc.

  • VSCode v1.19.1
  • Linux Elementary (latest)
  • LLDB Debugger 0.7.3

The LLDB is what is shown in VSCODE plugin, but when I do lldb --version from the terminal it says: lldb version 3.8.0 ( revision ).

I get no errors when starting lldb from the terminal. All breakpoints are hit while debugging, I just cannot see any of the variable values.

For the sake of completeness, I verified python scripting support as a Prerequisite listed on: https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

**

python-lldb-3.8 is already the newest version

**

No local or watch

1
  • 1
    I may have found the solution buried within the vscode manual that lists a bug for the current version of lldb i am using:: github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md Note: There is a known incompatibility of debug info emitted by rustc and LLDB 3.8: you won't be able to step through code or inspect variables if you have this version I will try to upgrade or downgrade and report back Commented Jan 3, 2018 at 22:59

3 Answers 3

6

The correct solution was to install LLDB 3.9. I can now inspect local variables, use the watch window, and see values via tooltips.

Here are the steps:

  1. Install LLVM 3.9. I found the accepted answer in this SE post to be the easiest way.
  2. Update Python LLDB to this version as per the vscode-lldb wiki. For example, I ran sudo apt-get install python-lldb-3.9
    1. Since LLVM now is invoked as llvm-3.9 (instead of just llvm) then VSCode may not recognize it and complain that LLVM is not installed or supported. My solution (yours may vary) was to remove then reinstall the VSCode extensions "LLDB Debugger 0.7.3" and "Native Debug 0.21.2"

Once this was done and VSCode was restarted, I started to debug with F5 then VSCode gave me an alert that a different LLDB was found (3.9) and asked to update to new executable - say yes and you should be good to go.

Results:

debugging session

Sign up to request clarification or add additional context in comments.

2 Comments

I am using code 1.41.1 on Ubuntu 18.04, VSCode does not prompt me for different LLDB version. It will be very helpful if you can share your launch.json file.
So, I'm using rust-analyzer and lldb and debugging works fine if I use the code lens rust-analyzer adds. However, if one of my variables has a very long value (let's say a Json payload) and I try to copy the value from the debug windows it will stop at one point and return an ellipsis so the value is not complete. Is there a way to get the complete value for long variables? I hope I'm just missing something
2

lldb doesn't "real" have support for Rust. It uses the C++ type system to support Rust types, and uses the C++ expression parser for expressions. So while simple things should work, more complex language features aren't well supported by "rust as C++".

It's possible to add language support for languages not directly supported by the clang front-end to lldb (see for instance the Go & OCaml support).

Tom Tromey is working on an actual Rust port for lldb, see: https://archive.fosdem.org/2018/schedule/event/rustdebug/ where he discusses this project, for instance. He hasn't submitted the results to mainline lldb yet, but his fork is available at https://github.com/rust-lang-nursery/lldb/commits/rust if anybody interested in Rust debugging in lldb wants to lend a hand.

6 Comments

lldb doesn't have support for Rust — citation and/or clarification required. Counterpoints 1, 2, 3.
@Jim - from all of my research it appears to be mentioned many times over with people successfully using LLDB with Rust on Linux, for example: marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb (which mentions Rust support in last bullet) klausi.github.io/rustnish/2017/05/28/…
How right you are. In late 2016 somebody instructed lldb to "pretend Rust is C++" as a workaround to not actually supporting Rust. So while I still contend it is correct to say lldb doesn't actually support Rust (since it is using a C++ compiler system to comprehend its types & parse expressions) to the extent that Rust looks like C++, printing variables should work after that patch. You're probably going to have a lot less luck with the expression parser, however.
What about for Windows? Install LLVM github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.8 Install Cygwin cygwin.com rustup install stable-x86_64-pc-windows-gnu rustup default stable-x86_64-pc-windows-gnu But from Watch window, variables still showing jibberish values?
|
0

This is for Windows users.

First, you'd try to install LLVM as suggestion above:

Install LLVM https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.8

Install Cygwin https://cygwin.com/

rustup component add rust-src rust-analysis rust-lldb

Then, switch to GNU Tool chain:

rustup install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu

When you cargo build, you'd quickly run into errors for example:

C:/gcc/bin/../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgcc_eh: No such file or directory
collect2.exe: error: ld returned 1 exit status

Depends on what you included in Cargo.toml, you may have many more errors.

To fix:

Option 1. you can revert to MSVC toolchain:

rustup default stable-x86_64-pc-windows-msvc
                    

However, you'd be back to square one: What you see in VSCode Watch Window is still Jibberish

Option 2. Install Cygwin

https://www.mingw-w64.org/downloads/

Add C:\cygwin64\bin to PATH

Then switch to GNU Tool chain, try cargo build. Does it works? Remember "Select Packages", choose all gcc's related and install source as well.

  • gcc-core
  • gcc-debuginfo
  • mingw64-x86*

If installer complains file corrupted or mirror don't have package you need, choose another mirror and try again.

Suggest:

Also, in the Select Packages window, search for openssl and openssl-debuginfo. Install the following packages from the Libs and Devel categories:

  • libopenssl-devel
  • libopenssl100 or libopenssl3

If you can't find a package from cygwin mirror, try Msys2. For example, I can't find libopenssl-dev, libopenssl100, or libopenssl3 from any of the mirror, I used Msys2 to finish the job.

pacman -S mingw-w64-x86_64-openssl mingw-w64-x86_64-pkg-config

Option 3. Install Msys2 https://www.msys2.org/

PATH should point to C:\msys64

Bring up MSYS2 command prompt: clang32.exe

Update package manager:

pacman -Syu
                            

Install MinGW-W64:

pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-openssl mingw-w64-x86_64-pkg-config
pacman -S mingw-w64-x86_64-zstd

Now, to remove a package:

pacman -Rns mingw-w64-x86_64-zstd

And again, if you can't find a package in msys2, go back to cygwin and see if you can find it in one of the mirrors.

And in the end, I managed to cargo build, F5/Debug from VSCode on my windows laptop AND FINALLY be able see my variables and their values from Watch window!!!

enter image description here

Overall this been a very painful process. Hope this will help.

Fyi, I still can't resolve one problem

solana-client = "2.0.13"  <-- Bad
solana-sdk = "2.0.13" <-- OK

Problem:

cargo:warning=zstd/lib/compress\zstd_compress_literals.c:14:10: fatal error: zstd_compress_literals.h: No such file or directory
     14 | #include "zstd_compress_literals.h"
        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~

I am an engineer/trader. I think I have better things to do.

Fyi, launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug siglib_rs",
            "program": "${workspaceFolder}/target/debug/myapp",
            "preLaunchTask": "cargo build",
            "cargo": {
                "args": ["build"],
                "filter": {
                    "name": "myapp",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

Also when you're installing so many things, you may blow your c-drive. Check what's eating up disk space you need wsl, and du command.

C:\Users\xxx\AppData
wsl
du -h /mnt/c/Users/xxx/AppData/Local --max-depth=2

Also, fyi, ... a few weeks later, with GNU Tool Chain: enter image description here The experience for Windows users is just terrible.

Final Solution

Out of desperation, I found this. And decided to try C/C++ Extension with MSVC toolchain enter image description here

And from launch.json (type from lldb to cppvsdbg):

{
    "version": "0.2.0",
    "configurations": [
      {
        "type": "cppvsdbg",
        "request": "launch",
        "name": "Debug executable 'rust'",
        "program": "${workspaceFolder}/target/debug/rust.exe",
        "args": [],
        "cwd": "${workspaceFolder}",
        "environment": [],
        "console": "integratedTerminal",
        "preLaunchTask": "cargo build"
      }
    ]
  }

And tasks.json (For preLaunchTask):

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "cargo build",
        "type": "shell",
        "command": "cargo",
        "args": ["build"],
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "problemMatcher": ["$rustc"]
      }
    ]
  }
  

Then everything worked again!! enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.