[英]How to debug Rust and WebAssembly program with VSCode and CodeLLDB?
我正在編寫Rust 和 WebAssembly 程序。 我想用 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。
這可能不是最有用的答案,但答案是您目前不能 - wasm-bindgen repo 有一個未解決的問題跟蹤未來對調試的支持,但尚不支持: https://github.com/rustwasm/ wasm-bindgen/issues/2389
請注意,即使是這樣,您也需要使用瀏覽器 DevTools 而不是 CodeLLDB 進行 WebAssembly 調試,因為您需要一個支持 JavaScript 的環境。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.