Rust的逐步交互式调试器?

问题描述 投票:37回答:4

如何以交互方式逐步调试Rust应用程序,就像我可以在Ruby中使用“pry”一样?

我想能够在达到断点时实时查看并优选地更改变量。是否有任何生产准备完成的项目?

debugging rust
4个回答
23
投票

我发现VS CodeCodeLLDB扩展程序具有良好的可用性:

  1. Install VS Code
  2. 从VS Code中搜索并安装Rust (rls)
  3. Install LLDB
  4. 从VS Code中搜索并安装CodeLLDB
  5. LLDB调试器添加了主菜单项“Debug”,从中可以启动调试器。首次启动调试时,必须选择环境(调试器):选择LLDB。
  6. 当你选择LLDB时,会打开一个launch.json文件,如果没有,打开它,它在.vscode文件夹下
  7. 你的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"] } ] }
  1. 如果你想保持通用性并且只编译与货物文件夹名称匹配的二进制文件,你可以使用$ {workspaceRootFolderName}变量替换“program”键: { "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的博客文章:


18
投票

Rust编译器生成具有本机调试信息(符号)信息的本机二进制文件,因此任何本机调试器都可以。这意味着gdblldb,或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


6
投票

对于图形调试器,有gdbgui。它适用于Linux,Windows和MacOS。它使用浏览器作为显示并与调试器进行交互。


0
投票

我有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()>}}}

© www.soinside.com 2019 - 2024. All rights reserved.