Visual Studio Rust



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.

Code

Visual Studio integration for the Rust programming language (http://www.rust-lang.org/). 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. C: rustup install stable-gnu 6. Set the active toolchain. We now need to set the Rust GNU toolchain as the active toolchain. Install a build of Visual Studio (15.8 preview 3 or newer). Install rustup (Rust toolchain manager). Install this extension from the marketplace Open a Rust project (File Open Folder.

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

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). You can either install the rust-analyzer extension from the Visual Studio Marketplace, or you can open VS Code, and search for rust-analyzer in the extensions menu (Ctrl+Shift+X). For debugging support, install the CodeLLDB extension.

The crates extension helps me managing packages in the project. [1]

rust-analyzer

Rust Vscode Debug

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)

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

Visual Studio Rust

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.

Visual Studio Rust Extension

I can use a step-by-step debugger as the following image. On the left sidebar, we can see the variable ‘a’ is 3.

Visual Studio Rust Build

References