"Error: there's no debug target!" with rust-analyzer VSCode

Hey folks, wondering what the recommended solution here is.

I have a library-only crate with an example that keeps segfaulting, and I'd like to debug it. I get the error in the topic title whenever attempting anything related to launching, debugging, etc.

I guess if I was working on a library crate with a binary, or a binary crate, this would be a no-brainer. However, I'm wondering how to go about debugging a library by way of its example? Is there something in Cargo.toml I need to set up indicating that the example should be the default target when building, or do I need to do something via VSCode? I've only been using VSCode for a few months, so could be missing something very obvious. Though I've successfully debugged other projects before, so I'm guessing I either need to configure my crate or my project to handle this case.

Thanks.

With the CodeLLDB extension installed, when I choose "Add Configuration..." from the "Run" menu, this dialog appears:

Cargo.toml has been detected in this workspace.
Would you like to generate launch configurations for its targets?

After I click "Yes", I have an auto-generated launch.json for each of the binary, example, test, and bench targets in my project. For example, this is the configuration it auto-generated for one of the examples:

        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug example 'raw_pointer'",
            "cargo": {
                "args": [
                    "build",
                    "--example=raw_pointer",
                    "--package=nalgebra"
                ],
                "filter": {
                    "name": "raw_pointer",
                    "kind": "example"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
3 Likes

Thanks, that works!

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.