如何使用 VSCode 和 LLDB 检查局部变量或将 watch window 与 Rust 代码一起使用?

How do I inspect local variables or use the watch window with Rust code using VSCode and LLDB?

我正在尝试使用 VSCode 调试 Rust 应用程序,但我无法检查任何局部变量或使用手表 window(见附件)。

所有断点都工作正常,我只是无法查看任何变量等

LLDB 是 VSCODE 插件中显示的内容,但是当我从终端执行 lldb --version 时,它说:lldb version 3.8.0 ( revision ).

从终端启动 lldb 时我没有收到任何错误。调试时所有断点都命中,我就是看不到任何变量值。

为了完整起见,我验证了 python 脚本支持作为先决条件列出: https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

**

python-lldb-3.8已经是最新版本

**

lldb "real" 不支持 Rust。它使用 C++ 类型系统来支持 Rust 类型,并使用 C++ 表达式解析器来处理表达式。因此,虽然简单的事情应该可行,但 "rust as C++" 无法很好地支持更复杂的语言功能。

可以为 lldb 的 clang 前端不直接支持的语言添加语言支持(例如,参见 Go 和 OCaml 支持)。

Tom Tromey 正在为 lldb 开发一个实际的 Rust 端口,请参阅:https://archive.fosdem.org/2018/schedule/event/rustdebug/ where he discusses this project, for instance. He hasn't submitted the results to mainline lldb yet, but his fork is available at https://github.com/rust-lang-nursery/lldb/commits/rust 如果任何对 lldb 中的 Rust 调试感兴趣的人想伸出援助之手。

正确的解决方案是安装 LLDB 3.9。我现在可以检查局部变量,使用监视 window,并通过工具提示查看值。

步骤如下:

  1. 安装 LLVM 3.9。我发现 the accepted answer in this SE post 是最简单的方法。
  2. 根据 the vscode-lldb wiki 将 Python LLDB 更新到此版本。比如我运行sudo apt-get install python-lldb-3.9
    1. 由于 LLVM 现在被调用为 llvm-3.9(而不仅仅是 llvm),因此 VSCode 可能无法识别它并抱怨未安装或不支持 LLVM。我的解决方案(您的可能会有所不同)是删除然后重新安装 VSCode 扩展 "LLDB Debugger 0.7.3" 和 "Native Debug 0.21.2"

完成并重新启动 VSCode 后,我开始使用 F5 进行调试,然后 VSCode 提醒我发现了一个不同的 LLDB (3.9) 并要求更新到新的可执行文件 - 说是,你就可以开始了。

结果: