Search results for 'rust', Visual Studio Code on marketplace.visualstudio.com. Installing Rust and VSCode The best way to install Rust is via Rustup You can grab Visual Studio Code from here You may also need to run rustup component add rust-src if you wish to step into standard library components (mentioned below). I want to build a rust-project from visual studio 2019 (windows). Here is what I have done so far: Downloaded and installed rust. Compiling via rustc from the command line is possible. Installed the Rust Add-On in Visual Studio. Set 'Toolchain to use' from 'nightly' to 'beta'. This solved an issue where I got the message that rls could not be. Shows how to build & debug Rust in VS Code.In this case, demonstrated from linux. To start using Rust, download the installer, then run the program and follow the onscreen instructions. You may need to install the Visual Studio C Build tools when prompted to do so. If you are not on Windows see 'Other Installation Methods'. Download rustup-init.exe (32-bit).
- Rust Visual Studio Code Setup
- Rust Visual Studio Codes
- Debug Rust Vscode
- Rust Hello World Visual Studio Code
At the very beginning, I want to share my development environment for Rust. While I’m writing, I changed my mind in the middle of writing adding debugger’s too. It seems more valuable to help others.
I use the Visual Studio Code for creating Rust applications. My environment is not the best. To hear about your development environment, I want to share mine first. Please share your environments in replies. I’m open to the new one. For simplicity and lightweight, I select the Visual Studio Code. It’s powerful too. Then, the most important things are the extensions.
Extensions
crates
The crates extension helps me managing packages in the project. [1]
rust-analyzer
While programming in Rust, it gives me warnings, errors, and hints when calling functions. It boosts productivity a lot. [2]
I try to find about debugging in Rust. How we can use debugger with the Visual Studio Code.
dbg! macro - the Basic
First, the most basic one prints the variable, or we can use println! macro.
The dbg macro[3] gives more information than the println macro. It shows a line number and a file name too.
gdb(pwndbg)
Rust Visual Studio Code Setup
I think the pwndbg [4] makes the GDB [5] more visually friendly. Unfortunately, I have been failed to use the pwndbg since this issue arises [6]. I saw how does it look like while debugging. The package brings the debugged source code to the top part of a screen. Instead of pure GDB, I can debug by watching the source.
Here are postings about how to use pwndbg. https://blog.xpnsec.com/pwndbg/https://www.ins1gn1a.com/basics-of-gdb-and-pwndbg/
CodeLLDB - Step by Step Debugger
I followed these steps [7] to install the CodeLLDB [8]. It’s an extension in the Visual Studio Code. All the steps are working. My versions are followings.
In step 7, I need to set “launch.json” and I used this.
I can use a step-by-step debugger as the following image. On the left sidebar, we can see the variable ‘a’ is 3.
References
I recently wanted to debug a Rust program on Windows that I had written, and was struggling with how to get it to work. Since there was quite a lot of hoops to jump through to get it to work, I though I should share it with other people as well. I've written this blog post from memory and I'm far from an expert in LLVM or Rust, so if you see something strange here then let me know.
The drawback of this approach is that you can't debug applications built using the MSVC toolchain. If you know how to do this, please tell me. I would really appreciate it.
UPDATE 2018-02-02:
As Stuart Dootson pointed out to me, there's a guide on how to debug applications using the MSVC toolchain here. I haven't tried this out myself, but it looks promising. Thanks Stuart!
1. Install LLVM
First we need to install LLVM which is a compiler infrastructure. Part of LLVM is LLDB which is the debugger we're going to use. The latest version of LLVM doesn't include Python support for LLDB which is required for the VSCode extension, so we need to download a custom built version and install that.
2. Install Python
We now need to install Python v3.5 (Not v3.6).
https://www.python.org/downloads/release/python-354/
If you installed the x64 version of LLVM, make sure that you install the x64 version of Python as well, otherwise you will encounter problems later on.
3. Make sure it works
Make sure that lldb can use scripting. If this doesn't work, make sure that both LLVM and Python is on PATH.
Write exit()
to close the Python interpreter and then CTRL+C
to break out of LLDB.
4. Install the VSCode extension
We now need to install the vscode-lldb
extension for Visual Studio Code. This is what makes it possible to debug our Rust code from Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
5. Install the Rust GNU toolchain
Since LLDB doesn't work with the msvc compiler, we need to install the Rust GNU toolschain and use that one. This have some drawbacks though such as we won't be able to intop with software produced by Visual Studio.
6. Set the active toolchain
Rust Visual Studio Codes

We now need to set the Rust GNU toolchain as the active toolchain. We do this by using the rustup
command again.
Debug Rust Vscode
We should now verify what our toolchain configuration look like by using rustup show
.
7. Create a project
Create a new project called hello_world
.
Open Visual Studio Code and go to ./src/main.rs
and place a breakpoint.
8. Edit launch.json
Press F5 to run the project. A selection box will appear that will ask you what environment you want to use. Choose LLDB Debugger
here. This will open up the launch.json
file, and here we need to tell Visual Studio Code how to launch our project. Edit the file so it looks similar to this:
9. Profit
Rust Hello World Visual Studio Code
Press F5 again. You should now be debugging your code.

Comments are closed.