Stream: wasmtime

Topic: debug crashing wasm


view this post on Zulip Hanif Ariffin (Feb 05 2023 at 16:07):

How do I debug a wasm that is crashing? lets say I have something like this

    thread::spawn(move || {
        let instance = linker.instantiate(&mut store, &module).unwrap();
        let handle_rpc = instance
            .get_typed_func::<(), (), _>(&mut store, "handle_rpc")
            .unwrap();
        for msg in io_rx {
            if let Ok(msg) = serde_json::to_string(&msg) {
                let _ = writeln!(stdin.write().unwrap(), "{msg}");
            }
            let _ = handle_rpc.call(&mut store, ());
        }
    });

and io_rx is a channel receiver, lets say a message causes the instance to crash. How do I get back some information? Is the a handler that I can pass to instance that gets executed when the wasm itself crash?

view this post on Zulip bjorn3 (Feb 05 2023 at 16:45):

If the wasm code traps, you will get an error result returned from handle_rpc.call(). You should likely handle this error instead of throwing it away and silencing the lint against this using let _ =.

view this post on Zulip bjorn3 (Feb 05 2023 at 16:46):

The error result contains a backtrace of the wasm code. For as long as your module has a names section you will get names for all functions. If there is no names section, you will only get function indexes.


Last updated: Nov 22 2024 at 17:03 UTC