'Debugging Rust on Vscode : u8 not shown correctly
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
- I autogenerated
launch.json
(thx @Unapiedra) - Following this doc, I added this to my launch configuration
"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.
Solution 1:[1]
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}"
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Unapiedra |