daveleroy/SublimeDebugger

Unable to debug unit tests in Rust

Closed this issue · 3 comments

I am trying to debug unit tests in Rust in Sublime using SublimeDebugger.

When I run Add Configuration for CodeLLDB: Debug Cargo Tests, it generates the following configuration:

    "debugger_configurations":
    [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Cargo test",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--lib",
                ]
            },
            "args": []
        },
    ],

However, this will not run due to missing the program attribute. Adding "program": "${workspaceRoot}/target/debug/projectName" enables me to start the debugger...but when I start debugging, the debugger drops into the main function in the file rather than the unit tests. This link says to use cargo instead of program in VSCode. However, the cargo field seems to be entirely ignored by SublimeDebugger.

I don't think any of the cargo stuff is supported by the debug adapter its done inside the vscode extension here so it will not work unless someone reimplements it in the lldb adapter configuration in this package.

I was able to make things work by adding "program": "${workspaceRoot}/target/debug/deps/projectName-SHA" where the SHA is found from the output of cargo test --no-run. It's not ideal but it works!

For future reference or in case you or anyone else wants to work on this.

async def configuration_resolve(self, configuration: dap.ConfigurationExpanded):
is where one could add support for performing cargo operations based on the cargo configuration parameter and populating the program field with the results.

This would also need to use the existing async process functions or require adding some additional ones

def check_output(command: list[str], cwd: str|None = None) -> bytes: