windows下用vscode调试rust

1、vscode安装插件 C/C++ (ms-vscode.cpptools),安装后运行Run->Start Debugging会出现C++(GDB/LLDB)与C++(Windows)

windows下用vscode调试rust

  2、根据rust用的版本,如果用的是x86_64-pc-windows-msvc,调试时选择C++(Windows), 如果是x86_64-pc-windows-gnu,调试时选择C++(GDB/LLDB)。

选择C++(Windows)时, 会出现如下配置信息(launch.json),自己修改program,设置要调试的程序。(安装visual studio)

{
    // 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": [
        {
            "name": "(Windows) 启动",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/rust/rust-test/r019echo-async/target/debug/r019echo-async.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false
        }
    ]
}

选择C++(GDB/LLDB)时,会出现下面的信息,自己设置要调试的程序与gdb所在的路径。(安装 mingw64)

{
    // 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": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "输入程序名称,例如 ${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/path/to/gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

3、调试过程中,当要跟踪到rust内部代码时,会跳出如下提示框,这时需要建一个C:\rustc\b8cedc00407a4c56a3bda1ed605c6fc166655447的目录,并将用户目录下的.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\src拷到前面的目录下。这样就能跟踪到内部代码了。
windows下用vscode调试rust

相关推荐