Debugging Rust Apps with VS Code

Debugging Rust Apps with VS Code


Rust

Debugging your web app is tough especially when you write it in a statically-typed language like Rust (I think that also makes a good practice in Rust ecosystem where developers tend to write test code before implementation).

Anyway, this time I figured out how to debug Rust web apps using Visual Studio Code. It’s waaay easier than I expected.

Here is the instruction:

VS Code Extensions

First of all, you need to have these two extensions installed on your VS Code.

Launch.json

Create a new file in the root of your project called .vscode/launch.json, and write the configuration as follows:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "attach",
      "name": "Attach to Shuttle",
      "program": "${workspaceFolder}/target/debug/api-shuttle"
    }
  ]
}

The most important point to take into account here is that the program attribute must point to the binary that you want to debug.

Now it’s ready…

  • 1) On your VSCode, put a breakpoint anywhere you want to stop and inspect.
  • 2) Run your dev server (in this example, cargo shuttle run).
  • 3) Then press F5 (on macos, fn + F5) to start debugging.

Thanks for reading ✌️

© 2024 Hiro