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 anyhow::Result; 12 use wasmtime::*; 13 14 fn main() -> Result<()> { 15 // Load our previously compiled wasm file (built previously with Cargo) and 16 // also ensure that we generate debuginfo so this executable can be 17 // debugged in GDB. 18 let engine = Engine::new(Config::new().debug_info(true))?; 19 let mut store = Store::new(&engine, ()); 20 let module = Module::from_file(&engine, "target/wasm32-unknown-unknown/debug/fib.wasm")?; 21 let instance = Instance::new(&mut store, &module, &[])?; 22 23 // Invoke `fib` export 24 let fib = instance.get_typed_func::<i32, i32, _>(&mut store, "fib")?; 25 println!("fib(6) = {}", fib.call(&mut store, 6)?); 26 Ok(()) 27 } 28