【问题标题】:How to debug Rust and WebAssembly program with VSCode and CodeLLDB?如何使用 VSCode 和 CodeLLDB 调试 Rust 和 WebAssembly 程序?
【发布时间】:2021-04-10 09:32:13
【问题描述】:

我正在写Rust and WebAssembly program。我想用 VSCode 和 CodeLLDB 调试 Rust 和 WebAssembly 程序,但我得到了一个错误。我可以调试简单的 Rust 程序,但无法调试 Rust 和 WebAssembly 程序。 重现错误的步骤如下所示。

使用以下命令克隆 Rust 和 WebAssembly 项目模板:

cargo generate --git https://github.com/rustwasm/wasm-pack-template

然后,输入项目名称。我用了“富”。 在 foo/src/lib.rs 中添加测试

mod utils;

use wasm_bindgen::prelude::*;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

#[wasm_bindgen]
extern {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet() {
    alert("Hello, foo!");
}

// add this test.
#[test]
fn foo_test() {
    assert_eq!(1, 1);
}

在 foo_test() 处放置一个断点。然后,创建一个 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 unit tests in library 'foo'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--lib",
                    "--package=foo"
                ],
                "filter": {
                    "name": "foo",
                    "kind": "lib"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug integration test 'web'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--test=web",
                    "--package=foo"
                ],
                "filter": {
                    "name": "web",
                    "kind": "test"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

在我开始“在库 'foo' 中调试单元测试”后,我收到一条错误消息,“Cargo 没有生成匹配的编译工件”。我该如何解决这个错误?

我的设置:macOS Big Sur 11.2.3、Visual Studio Code(VSCode) 1.55.1、CodeLLDB 1.6.1、cargo 1.51.0。

【问题讨论】:

    标签: macos visual-studio-code rust webassembly codelldb


    【解决方案1】:

    这可能不是最有帮助的答案,但答案是您目前不能 - wasm-bindgen repo 有一个未解决的问题跟踪未来对调试的支持但尚不支持:https://github.com/rustwasm/wasm-bindgen/issues/2389

    请注意,即使是这样,您也需要使用浏览器 DevTools 而不是 CodeLLDB 进行 WebAssembly 调试,因为您需要一个支持 JavaScript 的环境。

    【讨论】:

      猜你喜欢
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 2023-03-12
      • 2019-06-27
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多