How to Debug Rust in VS Code

Install the Rust extension, enable debug symbols in Cargo.toml, and configure launch.json to debug Rust code in VS Code.

Install the official Rust extension and configure the Cargo.toml to enable debugging symbols.

  1. Install the rust-lang.rust-analyzer extension from the VS Code Marketplace.
  2. Add debug = true to your [profile.dev] section in Cargo.toml to ensure debug info is generated.
  3. Create a .vscode/launch.json file with the cargo configuration to run the debugger.
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug",
      "type": "lldb",
      "request": "launch",
      "cargo": {
        "args": ["run", "--bin", "your_binary_name"]
      },
      "cwd": "${workspaceFolder}"
    }
  ]
}
  1. Set a breakpoint in your code and press F5 to start debugging.