DEV Community

Brian Horakh
Brian Horakh

Posted on

VsCode Debug RUST

This guide is intended to explain how to use the VSCode LLDB debugger with RUST.

Cunningham's Law states "the best way to get the right answer on the internet is not to ask a question; it's to post the wrong answer." The concept is named after Ward Cunningham, the inventor of wiki software.

With the Cunningham spirit in mind, if you know a better way to do this, or other cool stuff I should try please let me know in the comments.

Resources I used:

CodeLLDB natively supports visualization of most common Rust data types:

Built-in types: tuples, enums, arrays, array and string slices.
Standard library types: Vec, String, CString, OSString, Path, Cell, Rc, Arc and more.

Below is a fully functioning launch.json for vscode that works with rust 1.60, inline comments:

{
    "version": "0.2.0",
    "configurations": [
        {
            // πŸ˜“ LLDB Help: https://github.com/vadimcn/vscode-lldb/discussions
            "type": "lldb",
            "request": "launch",
            "name": "Debug",

            // πŸ€“ use this to debug RUST binaries:
            "program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}",

            // πŸ€“ use cargo for libraries
            /* 
            "cargo": {
                "args": ["test", "--no-run", "--lib"], // Cargo command line to build the debug target
                // "args": ["build", "--bin=foo"] is another possibility
                "filter": { // Filter applied to compilation artifacts (optional)
                    "name": "mylib",
                    "kind": "lib"
                }            
            */
            "args": [],
            "cwd": "${workspaceFolder}",
            "sourceLanguages": ["rust"], // required to add support for Vec, String, enum .. 
            "terminal":"integrated",        // can also be 'console', 'external'

            // πŸ€“ https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#stdio
            "stdio": null                // connect all streams to default terminal, can also use file(s)

            // "stopOnEntry":true,          // should open an lldb hex/asm dump on start
        ]
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)