How to run a [[bin]] in VS Code in debug mode?

Sorry for a trivial question, but googling leads me to trivial first-time walk-throughs of VS Code.

A year ago, I tried VS Code and probably CodeLLVM debugger, and did debug some simple crate (with code in main.rs) with breakpoints.

Now I've installed VS Code again and am completely lost.

I have a project with couple of binaries and want to debug one, step by step. Extensions I've got: 1. Rust analyzer, 2. CodeLLVM, 3. cargo and 4. crates.

Made an automatic configuration json file via some menu (see below), and it made tests as the first configuration. I want to run the 4th configuration, but can't see how. The only thing it always runs is the first config, which simply does cargo test.

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests in library 'route'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--lib",
                    "--package=route"
                ],
                "filter": {
                    "name": "route",
                    "kind": "lib"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug executable 'astar'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=astar",
                    "--package=route"
                ],
                "filter": {
                    "name": "astar",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests in executable 'astar'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--bin=astar",
                    "--package=route"
                ],
                "filter": {
                    "name": "astar",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
        {
            // tihs is what I want to run
            // equivalent of `cargo r --bin alt ../data/ala/bus.csv`
            "type": "lldb", 
            "request": "launch",
            "name": "Debug executable 'alt'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=alt",
                    "--package=route",
                    "../data/ala/bus.csv"
                ],
                "filter": {
                    "name": "alt",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests in executable 'alt'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--bin=alt",
                    "--package=route"
                ],
                "filter": {
                    "name": "alt",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
    ]
}

At the top of Run and debug tab, right after the green triangle run button, there's a drop down list to select which configuration to run.

1 Like

Oh, what a sneaky button! Thanks a lot!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.