cargo-aoc icon indicating copy to clipboard operation
cargo-aoc copied to clipboard

How do I debug with cargo-aoc

Open dantho opened this issue 4 years ago • 3 comments

I'm having no luck debugging (using VS Code and ) while running with cargo-aoc. The debugger ignores my break-traps in dayN.rs I'm a bit of a newbie. This should work, right? Is there something in this .vscode launch.json file that's wrong? (I can debug Hello World with a similar setup.)

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/target/debug/advent-of-code-2020.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false
        }
    ]
}

dantho avatar Dec 12 '20 21:12 dantho

cargo aoc generates a new, nested Rust project under target/aoc; the binary you want to run is target/aoc/aoc-autobuild/target/release/aoc-autobuild. This is generated, built and run when you use cargo aoc on the command-line. Make sure you run cargo aoc before debugging; the generated code applies to a single day (by default, the most recent, use the command-line switches to change what day driver is generated).

I opened a feature request (two years ago) to help with debugging by only generating the binary, not also run it (see #64, PR in #69), but neither have seen movement unfortunately.

In the meantime, I use vscode-lldb features to trigger a build and extract the right binary path for the debugger, I don't know if cppvsdbg has something similar. For lldb, don't set program, but set cargo instead, and have it run cargo build --manifest-path target/aoc/aoc-autobuild/Cargo.toml --bin=aoc-autobuild; lldb will extract the right binary and you can then start debugging. This will only work if cargo aoc was run before to generate the nested project.

mjpieters avatar Dec 04 '21 19:12 mjpieters

Thanks for the reply, @mjpieters !

Because of your reply, I finally dug in and got Rust debugging working in VS Code. I tried using whatever debugger I had installed, and the executable you pointed me to. It didn't work. But then I loaded the VSCode Add-in "CodeLLDB", ran its command "LLDB: Generate Launch Configurations from Cargo.toml" and I can now debug my code and my tests!

Love it. Thanks again.

dantho avatar Dec 06 '21 03:12 dantho

For anyone else that comes across this issue, this is the launch.json that worked for me:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug current day",
            "cargo": {
                "args": [
                    "build",
                    "--manifest-path=target/aoc/aoc-autobuild/Cargo.toml",
                    "--bin=aoc-autobuild"
                ],
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

MaddyGuthridge avatar Dec 20 '23 12:12 MaddyGuthridge