Rust: VSCode debug設置


Rust: VSCode debug設置

前提

  1. 切換到msvc toolchain by rustup default stable-x86_64-pc-windows-msvc

步驟

Install Rust and VS Code

This should go without saying.

Install Rust
Install Visual Studio Code

Install VS Code Extensions

You'll need to install an extension. Which one depends on your platform.

C/C++ (Windows)
CodeLLDB (OS X / Linux)

It probably makes sense to go ahead and install the Rust extension as well.

Configure VS Code

Now that your tools are installed you need to configure your VS Code launch properties.

Click Debug -> Add Configuration
If you're on Windows then select C++ (Windows)
If you're on Mac or Linux then select LLDB: Custom Launch

This should create and open launch.json. You'll have to manually change the executable name under "program".

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/foo.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "(OSX) Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/foo",
            "args": [],
            "cwd": "${workspaceRoot}",
        }
    ]
}

Text above can be copy-pasta'd.

Next, you should verify breakpoints are enabled. Some readers have reporting needing to this do. Some machines have it enabled by default. 🤷‍♂️

Breakpoint settings

File -> Preferences -> Settings

That's it!

Add a breakpoint. Press F5 to launch. Voila!

Ref

https://www.forrestthewoods.com/blog/how-to-debug-rust-with-visual-studio-code/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM