在Visual Studio Code中使用gdb调试Rust时未命中断点



我开始学习 Rust,我想在 Visual Studio Code 中设置调试,但无法让断点工作。我使用 VS Code 的 Native Debug 和 RustyCode 扩展。

这是我的启动文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "gdb",
            "request": "launch",
            "target": "target/debug/test",
            "cwd": "${workspaceRoot}"
        }
    ]
}

但是当我运行此配置时,断点不会被命中。我在调试控制台中看到调试器启动并且应用程序运行良好,但有一条警告消息"未加载符号":

No symbol table is loaded.  Use the "file" command.
No symbol table is loaded.  Use the "file" command.
Running executable
[New Thread 32168.0x81e0]
[New Thread 32168.0x3360]
[New Thread 32168.0x61b8]
[New Thread 32168.0x8040]
The program "+ + * - /" calculates the value 1
[Thread 32168.0x61b8 exited with code 0]
[Thread 32168.0x3360 exited with code 0]
[Thread 32168.0x8040 exited with code 0]
[Inferior 1 (process 32168) exited normally]

这是我正在使用的应用程序的来源。如何使断点工作?

我遇到了同样的问题,直到我意识到我使用的是rustcmsvc版本。

GDB 只适用于gnu构建,因此如果您使用 rustup,解决方案就像 rustup default stable(或测试/每晚)一样简单。GNU 是默认的,对于 msvc,您需要执行stable-msvc )。

如果你不想使用 rustup,你应该手动重新安装 Rust 的 gnu 版本。

编辑:如下面的评论中所述,不要忘记重建!

我在断点方面遇到了类似的问题,发现将此行添加到 settings.json 修复了它:

{
    "debug.allowBreakpointsEverywhere": true
}

我也在使用Microsoft的C/C++调试器插件,而不是本机插件。它仍然适用于 GDB。

如前所述 - gdb调试器不能很好地与 rustc 构建msvc配合使用。Rustup 默认msvc现在在 Windows 上构建。
要将默认的 rustc 构建切换到 gnu您必须运行以下命令:

rustup default stable-gnu

最新更新