Compared to other tools, Visual Studio Code is a great code editor providing seamless integration with Rust projects in terms of LSP (Language Server Protocol) and DAP (Debugger Adapter Protocol). Configure LSP for Rust is easy for all the Rust tools but setting DAP for debugging may not be so straight forward. If you prefer a light-weight code editor with seamless DAP integration then VS Code is a good choice.
Install Rust by following the instructions here.
Install Visual Studio Code.
From VS Code, press Ctrl-P (Command P for macOS), and enter
ext install rust-lang.rustto setup LSP support for Rust. You may be prompted to install other components by the extension.
Below are the different ways that you can use Visual Studio Code to debug your Rust projects.
LLDB Native Debugger
The LLDB Debugger is the debugger component of the LLVM project.
In Visual Studio Code, press Ctrl-P (Command P for macOS), enter
ext install vadimcn.vscode-lldbto install CodeLLDB.
When it runs for the first time, the extension detects the Cargo project settings and creates a launch.json. After that you can set breakpoints and press F5 to start debug your application.
We are going to use cargo-debug instead of
# cargo install cargo-debug
Once installed you can use lldb to debug the code in terminal.
Debug using the LLDb debugger
# cargo debug --debugger=lldb
Once you are in lldb debugger, you can set breakpoint
breakpoint set -l 1 sets a breakpoint at line 1.
runto start debugging.