How to Debug Rust in VS Code(windows)
VS Code is the most popular code editor in this world currently. Almost all the Coding works I’m working on are based on VS Code. I love Emacs too, but it’s too hard to set up…
How to debug XXX is essential for every programming language. I write this note about how to debug Rust in windows and VS Code.
There are only two steps we need to do:
- Install C++ extension.
- Write debug config for our project.
Install C++ Extension
We should install the C++ compiler and debugger before we install this extension. But I guess most of us have installed these during installing the Rust environment.
Searching c++
in extensions: marketplace of VS Code, select the most installed one, which was developed by Microsoft.
Write Debug Config
I know writing debug config by ourselves is a little boring because some kinds of configurations are hard to understand. Just follow the steps in my screenshot and put the following codes in our launch.json
, remember to change the project name!
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/your-rust-project-name.exe",
"cwd": "${workspaceRoot}",
"args": [],
"stopAtEntry": false,
}
]
}
Problems
I used this debug strategy for a couple of days, I found there may be some problems:
- You should run
cargo run/build
command after you modify your code.
References:
Debugging Rust with VS Code - DEV Community 👩💻👨💻
Last modified on 2021-12-20