【发布时间】: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