我尝试设置调试 Rust 一段时间了,但没能成功。我已经尝试了多种方法,但无论如何它都不起作用。当我尝试启动新会话时,它只运行可执行文件并结束会话,而不让我尝试调试它。那是没用的。
这是演示该错误的视频。这里我已经运行了
rustc demo.rs
所以我已经有了演示可执行文件。我只是无法运行调试器本身。
https://drive.google.com/file/d/1I7WuyZi3ewYzq3_8XB9sHauHCgTICEXr/view?usp=sharing
我使用 nvim-dap 进行主要调试,还使用 rustaceanvim,它是 rust-tools 本身的一个新分支(因为 rust-tools 无论如何都已存档)。 Rustaceanvim 这么说
This is a filetype plugin that works out of the box, so there is no need to call a setup function or configure anything to get this plugin working.
这就是为什么除了一些键盘映射之外我没有为 rustaceanvim 设置任何内容。我主要就是这样配置nvim-dap本身。
local dap = require("dap")
dap.adapters.codelldb = {
type = "server",
host = "127.0.0.1",
port = "${port}",
executable = {
command = "$HOME/.local/share/nvim/mason/bin/codelldb",
args = { "--port", "${port}" },
},
}
dap.configurations.rust = {
{
name = "Launch",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
},
}
无论我尝试什么,行为仍然是一样的。
这也是我的 neovim 配置:https://github.com/imindMan/arch-config/tree/master/config/nvim。
看起来您直接使用 nvim-dap 来手动配置调试适配器客户端,而不是 rustaceanvim。
rustaceanvim 有一个
:RustLsp debuggables
命令,可以在 rust-analyzer 中查询调试目标并在启动调试会话之前构建它们。
如果在 LSP 客户端启动后发现,它们也应该在运行 DapContinue
时出现。
Afaik,这仅适用于货运项目。
如果您使用
rustc
,您应该查看 命令行参数文档。
也许
:包含调试信息-g
会有帮助。