在Windows上的LLDB中运行Rust OpenGL程序时窗口无法打开



我在Windows上有一个最小的Rust/OpenGL应用程序。我使用的是Visual Studio代码、LLDB和Glutin(一个类似GLFW的库)。

通过cargo run启动会打开一个空窗口,但通过LLDB启动时,不会打开任何窗口。我已经在LLDB和println!中确认了上下文创建函数正在被调用,并且主循环正在执行。换句话说,我已经验证了所有代码行都已到达。无论是否从VSCode中运行,都是如此。

我使用的是32位Rust工具链stable-i686-pc-windows-gnu,因为LLDB并不完全支持64位Windows。除此之外,内陆发展中国家似乎正在按预期开展工作。

以下是main.rs,它改编自谷蛋白自述。(Glutin是一个类似于GLFW的Rust库。)除了打开窗口所需的基本内容外,我已经删除了所有内容。

所需行为:当程序从LLDB启动时,窗口将打开,与程序从外部LLDB启动相同。

实际行为:当程序从LLDB启动时,窗口不会打开。

问题:什么可以解释这种行为差异?也就是说,当LLDB从终端打开时,为什么窗口不会从LLDB打开?


extern crate gl;
extern crate glutin;
fn main() {
let events_loop = glutin::EventsLoop::new();
let window = glutin::WindowBuilder::new();
let context = glutin::ContextBuilder::new();
// When running outside LLDB, this line causes the window to appear.
// The let binding is necessary because without it, the value will be dropped
// and the window will close before the loop starts.
let gl_window = glutin::GlWindow::new(window, context, &events_loop).unwrap();
// Normally, we'd make the window current here. But it's not necessary
// to reproduce the problem.
loop {
// This is where we'd swap the buffers and clear. But it's not necessary
// to reproduce the problem.
}
}

部分答案:作为一种变通方法,您可以LLDB附加到正在运行的进程,而不是从LLDB启动进程。在VSCode中,可以使用:Add Configuration -> LLDB: Attach by Name执行此操作。有了这个工作流程,OpenGL窗口就会打开,就像不涉及LLDB时一样。不幸的是,连接明显不符合人体工程学。

更新:我更喜欢使用调试器启动,而不是附加。我发现Rust的MSVC x64工具链以及微软的C/C++调试器在这个用例中运行得很好。对我有效的步骤是:

  1. 如有必要,安装MSVC工具链:rustup install stable-x86_64-pc-windows-msvc
  2. 将MSVC工具链设置为默认值:rustup default stable-x86_64-pc-windows-msvc
  3. 更新Rust:rustup update
  4. 为Visual Studio代码安装Microsoft的C/C++扩展。该扩展包括一个与Rust编译的MSVC二进制文件兼容的调试器
  5. 将调试配置添加到Visual Studio代码中。我一开始添加了默认配置,但不得不对其进行修改。最终,这就是我在.vs-code/launch.json中所拥有的内容——请注意,字符串rust-test对项目来说是唯一的:

-

{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/rust-test.exe",
"args": [],
"symbolSearchPath": "${workspaceFolder}/target/debug/rust-test.pdb",
"stopAtEntry": false,
"cwd": "${workspaceFolder}/target/debug",
"environment": [],
"externalConsole": true
}

如果有人对内陆发展中国家的问题有任何想法,我将不胜感激。虽然MSVC工具链目前解决了我的问题,但可能还有其他人真的想使用LLDB并遇到这个问题。

最新更新