Reputation: 456
I am debugging this simple Rust program on Vscode
fn main() {
let u8: u8 = 3;
let b: u16 = 5;
let c: u32 = 7;
let d: u64 = 9;
}
The values of these variables are displayed correctly, except for u8
I'm curious, is there a reason or a solution for this issue? Thank you!
Edit
Here's my launch.json
configuration. I also followed a tutorial and installed the C/C++ extension with "type": "cppvsdbg"
, but it gives me the same result.
I'm also adding that I am a Rust newbie :)
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<your program>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
Edit Thanks to @Unapiedra & @ChayimFriedman, for their answers and insights. I couldn't solve this problem. But here's what I tried, someone might pick it up in the future
launch.json
(thx @Unapiedra) "preRunCommands": [
"type format add --format hex int" // This is a test from lldb.llvm.org/use/variable.html
]
But it didn't work. I also tried initCommands
to no avail.
Upvotes: 5
Views: 2776
Reputation: 26
Open your Visual Studio Code setting (File -> Prefrences -> Settings (Ctrl+))
Search for "debug" in the settings search bar.
Click on "Launch configuration defaults" under the "Extentions› CodeLLDB" section.
Click on "Edit in settings.json" on the right hand tab
in settings.json add "lldb.displayFormat": "hex"
alternatively set it to "decimal"
Upvotes: 0
Reputation: 16197
The reason this happens is because you are using the C++ extension not the Rust extension for the debugger.
LLDB or the debugger frontend in VSCode needs to guess the type of your a
variable. And it interprets the byte to show it in hex formatting.
On my setup, it works out of the box. I posted my launch.json
below. This was autogenerated by VsCode. I would guess that the RustAnalyzer extension is the driver of this.
The autogeneration was triggered by me clicking on the Debugging tab, then clicking on 'create a launch.json file'. And then I get a prompt that Cargo.toml has been detected and I can generate debug targets.
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'q72117996'",
"cargo": {
"args": [
"build",
"--bin=q72117996",
"--package=q72117996"
],
"filter": {
"name": "q72117996",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'q72117996'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=q72117996",
"--package=q72117996"
],
"filter": {
"name": "q72117996",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
Upvotes: 2