Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/examples/fib-debug/main.rs
1690 views
1
//! Example of enabling debuginfo for wasm code which allows interactive
2
//! debugging of the wasm code. When using recent versions of LLDB
3
//! you can debug this executable and set breakpoints in wasm code and look at
4
//! the rust source code as input.
5
6
// To execute this example you'll need to run two commands:
7
//
8
// cargo build -p example-fib-debug-wasm --target wasm32-unknown-unknown
9
// cargo run --example fib-debug
10
11
use wasmtime::*;
12
13
fn main() -> Result<()> {
14
// Load our previously compiled wasm file (built previously with Cargo) and
15
// also ensure that we generate debuginfo so this executable can be
16
// debugged in GDB.
17
let engine = Engine::new(
18
Config::new()
19
.debug_info(true)
20
.cranelift_opt_level(OptLevel::None),
21
)?;
22
let mut store = Store::new(&engine, ());
23
let module = Module::from_file(&engine, "target/wasm32-unknown-unknown/debug/fib.wasm")?;
24
let instance = Instance::new(&mut store, &module, &[])?;
25
26
// Invoke `fib` export
27
let fib = instance.get_typed_func::<i32, i32>(&mut store, "fib")?;
28
println!("fib(6) = {}", fib.call(&mut store, 6)?);
29
Ok(())
30
}
31
32