Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing variable values in Visual Studio code using Rust and CodeLLDB

When I am stepping through the code in the debugger, I've noticed that certain variables don't show values in the variables pane:

  1. Options: if a variable is an option, it doesn't show the value of the object in the option (if there is one). I believe it shows a ptr or other value
  2. HashMaps: I can't view the objects within the hashmap or their values.

Local variables (e.g., String, u64) show values normally.

Is this by design, or is there a way to view these values to make debugging easier? Thanks!

enter image description here

like image 357
Bobby Dore Avatar asked Oct 24 '25 16:10

Bobby Dore


1 Answers

Being able to see variables depends a lot on whether the compiler and the debugger fit together.

For example, if you run CodeLLDB, you want to make sure that your code is compiled with the GDB backend, not with the MSVC backend.

On the other hand, if you do compile with the MSVC backend, the ms-vscode.cpptools debugger might work better for you.

You can choose the debugger that rust-analyzer uses at:

Settings -> Extensions -> rust-analyzer -> debug -> Debug: Engine

You can switch the compiler toolchain by calling (assuming you are on windows):

  • rustup default stable-x86_64-pc-windows-msvc
  • rustup default stable-x86_64-pc-windows-gnu

(followed by cargo clean)

On Windows 11, I got the best results with:

  • x86_64-pc-windows-gnu + vadimcn.vscode-lldb (CodeLLDB)
  • x86_64-pc-windows-msvc + ms-vscode.cpptools

In those configurations, both were able to resolve the content of a HashMap.

like image 114
Finomnis Avatar answered Oct 26 '25 06:10

Finomnis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!