daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
372 stars 44 forks source link

Unable to debug unit tests in Rust #263

Closed jmd1011 closed 4 months ago

jmd1011 commented 4 months ago

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.

daveleroy commented 4 months ago

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.

jmd1011 commented 4 months ago

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!

daveleroy commented 4 months ago

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

https://github.com/daveleroy/SublimeDebugger/blob/cb9971093bdb255d943c6d0ae5caff3641130f2f/modules/adapters/lldb.py#L86 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 https://github.com/daveleroy/SublimeDebugger/blob/cb9971093bdb255d943c6d0ae5caff3641130f2f/modules/dap/transports.py#L43