13c51d3adSAlex Crichton //! Example of enabling debuginfo for wasm code which allows interactive 23c51d3adSAlex Crichton //! debugging of the wasm code. When using recent versions of LLDB 33c51d3adSAlex Crichton //! you can debug this executable and set breakpoints in wasm code and look at 43c51d3adSAlex Crichton //! the rust source code as input. 53c51d3adSAlex Crichton 63c51d3adSAlex Crichton // To execute this example you'll need to run two commands: 73c51d3adSAlex Crichton // 887016454SHiroki Noda // cargo build -p example-fib-debug-wasm --target wasm32-unknown-unknown 93c51d3adSAlex Crichton // cargo run --example fib-debug 103c51d3adSAlex Crichton 113c51d3adSAlex Crichton use wasmtime::*; 123c51d3adSAlex Crichton main() -> Result<()>133c51d3adSAlex Crichtonfn main() -> Result<()> { 143c51d3adSAlex Crichton // Load our previously compiled wasm file (built previously with Cargo) and 153c51d3adSAlex Crichton // also ensure that we generate debuginfo so this executable can be 163c51d3adSAlex Crichton // debugged in GDB. 17*96c905a6SAlex Crichton let engine = Engine::new( 18*96c905a6SAlex Crichton Config::new() 19*96c905a6SAlex Crichton .debug_info(true) 20*96c905a6SAlex Crichton .cranelift_opt_level(OptLevel::None), 21*96c905a6SAlex Crichton )?; 227a1b7cdfSAlex Crichton let mut store = Store::new(&engine, ()); 2315c68f2cSYury Delendik let module = Module::from_file(&engine, "target/wasm32-unknown-unknown/debug/fib.wasm")?; 247a1b7cdfSAlex Crichton let instance = Instance::new(&mut store, &module, &[])?; 253c51d3adSAlex Crichton 263c51d3adSAlex Crichton // Invoke `fib` export 27b0939f66SAlex Crichton let fib = instance.get_typed_func::<i32, i32>(&mut store, "fib")?; 287a1b7cdfSAlex Crichton println!("fib(6) = {}", fib.call(&mut store, 6)?); 293c51d3adSAlex Crichton Ok(()) 303c51d3adSAlex Crichton } 31