Skip to content

Instantly share code, notes, and snippets.

@vezaynk
Created April 21, 2019 00:05
Show Gist options
  • Save vezaynk/0c5f70392cfb627fc94ff727db5f1211 to your computer and use it in GitHub Desktop.
Save vezaynk/0c5f70392cfb627fc94ff727db5f1211 to your computer and use it in GitHub Desktop.
Simple setup for debugging rust in VSCode

It appears that as of the time of writing this, there is no official rust debugger. Luckily, there are two generic debuggers which seem to do the job alright: GDB, LLDB. Setting up both of them is basically the same process. So far, I had a nicer experience with LLDB so that will be the focus.

There are a few LLDB debuggers available for VSCode. The one I decided to use was CodeLLDB (vadimcn.vscode-lldb), but once again all of them should work almost the same way.

Here is the .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

You may notice that I had a preLaunchTask defined. The reason for this is that LLDB doesn't know how to rebuild your code. It is necessary to define that process:

.vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "cargo",
            "args": ["build", "-q"],
            "type": "process"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment