Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I debug with cargo-aoc #68

Open
dantho opened this issue Dec 12, 2020 · 3 comments
Open

How do I debug with cargo-aoc #68

dantho opened this issue Dec 12, 2020 · 3 comments

Comments

@dantho
Copy link

dantho commented Dec 12, 2020

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
        }
    ]
}
@mjpieters
Copy link

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.

@dantho
Copy link
Author

dantho commented Dec 6, 2021

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.

@MaddyGuthridge
Copy link

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}"
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants