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(Config::new().debug_info(true))?;
18     let mut store = Store::new(&engine, ());
19     let module = Module::from_file(&engine, "target/wasm32-unknown-unknown/debug/fib.wasm")?;
20     let instance = Instance::new(&mut store, &module, &[])?;
21 
22     // Invoke `fib` export
23     let fib = instance.get_typed_func::<i32, i32>(&mut store, "fib")?;
24     println!("fib(6) = {}", fib.call(&mut store, 6)?);
25     Ok(())
26 }
27