Debugging Rust code on WSL2

Harsimran Singh Maan
2 min readAug 14, 2020

If you are developing using Rust on Windows with a WSL2, adding support for debugging is very easy. If you haven’t started using WSL2(Windows subsystem for Linux 2) yet, you can follow my previous post on how to Install and setup Rust development environment on WSL2.

Install Debug Tools

We’ll write a new application to go through the setup steps. You can also clone the application from Github if you don’t want to set it up locally.

cargo init rustapp
cd rustapp
code .

For a linux backend(WSL2 in this case), install the CodeLLDB extension on Visual Studio Code.

Install the CodeLLDB extension

Configure the debugger

Once the extension is installed, setup a debug configuration by clicking Run -> Add Configuration from the VSCode menu. Add the following launch.json configuration. You would need to change the program path when setting up the debug config for a different project.

Save launch.json debug config

Start Debugging

Add a breakpoint in the rust file and hit Run -> Start Debugging or press the F5 key. You should see the the debugger pause at the breakpoint.

Debugger pauses at the breakpoint

You can step through the code using the standard debug commands or by using the Debug control buttons in VsCode.

Debugging supports looking into collections, watching variables and exposes the call stack

And that’s it! Have fun developing with Rust. 😃

--

--