wasmi
wasmi copied to clipboard
Add origin information about Wasm traps
Hi,
Is there any way to debug where trap happened? At least function would be good, file+line and/or traceback is even better.
I'm using rust's wasm32-unknown-unknown for generating wasm code itself (and the trap is a panic). Maybe that's something to tweak at the compiler side?
In general, there is no way to get location of the trap yet (although this should be very useful, and I think this is somwthing we want sooner rather than later)
However, it is possible to print information provided in panic payload, at least if you have a custom panic fmt. But im not sure how panics are reported in wasm32-unknown-unknown with std.
However, it is possible to print information provided in panic payload, at least if you have a custom panic fmt. But im not sure how panics are reported in wasm32-unknown-unknown with std.
It looks like payload is ignored by rust compiler: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/wasm32.rs#L28
Also, what do you mean by "print"? I don't think there is some builtin way to print something in wasm.
AFAIK, actual printing happens in the panic hook, ie here which happens before libpanic_* takes control (just take a look at other impls or at libpanic_abort).
Also, what do you mean by "print"? I don't think there is some builtin way to print something in wasm.
Yeah, you're right! However, in some envs such as web JS or wasmi we can define what it means to print something.
And, In fact, wasm std lib supports basic i/o however under special flag DEBUG
Hope this helps!
Wow, that worked like a charm! Thanks. Here is the code that catches panics and logs payload and location for anyone trying to figure it out.
However, I think this issue (i.e. tracking traps and not only panics out of the box) depends on debugging symbols and should not be closed yet. Right?
Im very happy thats worked!
And yea, you right, we still need to have means to debug different kinds of traps and print stacktraces. And yeah it depends on debugging symbols (although plain name section should do the trick for the start)
Closed in favor of https://github.com/paritytech/wasmi/issues/538.