如何以交互方式逐步调试Rust应用程序,就像我可以在Ruby中使用“pry”一样?
我想能够在达到断点时实时查看并优选地更改变量。是否有任何生产准备完成的项目?
我发现VS Code和CodeLLDB扩展程序具有良好的可用性:
launch.json
文件,如果没有,打开它,它在.vscode
文件夹下launch.json
应该是这样的:
{
// 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",
"program": "${workspaceRoot}/target/debug/hello_world",
"args": [],
"cwd": "${workspaceRoot}/target/debug/",
"sourceLanguages": ["rust"]
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceRoot}/target/debug/${workspaceRootFolderName}",
"args": [],
"cwd": "${workspaceRoot}/target/debug/",
"sourceLanguages": ["rust"]
}
]
}
这里有一些关于Rust和VS Code的博客文章:
Rust编译器生成具有本机调试信息(符号)信息的本机二进制文件,因此任何本机调试器都可以。这意味着gdb
和lldb
,或Windows调试器(WinDBG或只是Visual Studio),如果你使用的是MSVC ABI版本的Rust。如果你想要一个综合体验,RustDT是要走的路(在Windows上设置:How to set up GDB for debugging Rust programs in Windows?)。请注意,您可能会遇到Windows上的How can I inspect variable values while debugging MSVC ABI Rust programs?和Mac上的https://github.com/rust-lang/rust/issues/33062。
对于图形调试器,有gdbgui。它适用于Linux,Windows和MacOS。它使用浏览器作为显示并与调试器进行交互。
我有gdb 7.11和rust-gdb命令似乎提供了与gdb native相比更多的rust相关信息。例如,rust-gdb使用全名正确显示生锈对象,而gdb根本不显示它们。 在下面的示例中,gdb现在将显示所有粗体部分。
$ 1 = Args = {inner = ArgsOs = {inner = Args = {iter = IntoIter = {buf = NonNull = {pointer = NonZero <* const std :: ffi :: os_str :: OsString> = {0x7ffff6c20060}},phantom = PhantomData,cap = 1,ptr = 0x7ffff6c20060,end = 0x7ffff6c20078},_ dont_send_or_sync_me = PhantomData <* mut()>}}}