wasmi icon indicating copy to clipboard operation
wasmi copied to clipboard

Add origin information about Wasm traps

Open tailhook opened this issue 7 years ago • 5 comments

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?

tailhook avatar Jan 29 '18 16:01 tailhook

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.

pepyakin avatar Jan 29 '18 20:01 pepyakin

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.

tailhook avatar Jan 29 '18 21:01 tailhook

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!

pepyakin avatar Jan 29 '18 21:01 pepyakin

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?

tailhook avatar Jan 30 '18 00:01 tailhook

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)

pepyakin avatar Jan 30 '18 06:01 pepyakin

Closed in favor of https://github.com/paritytech/wasmi/issues/538.

Robbepop avatar Oct 25 '22 08:10 Robbepop