So RUST_BACKTRACE is never enabled in wasm32-unknown-unknown builds.
I'm wondering if there's another way of enabling backtraces. Is this possible? I asked this many times in different places before and the answer was always "no", but I'm wondering if anything changed.
If the answer is still "no" then there's no way to enable Rust backtraces in wasm32-unknown-unknown builds, which is unfortunate. Does anyone know any workarounds for this? Or any hacks? I searched for open issues in Rust GH page but couldn't find anything relevant.
WASM code doesn't have access to it's stack. If you are panicking, you should see an exception with a backtrace on the console that includes all javascript and WASM frames on the stack. If not, you will need to call into a javascript function that gets the backtrace using new Error().
I'm not talking about Wasm stack, I'm talking about Rust stack. Rust compiled to WASI or emscripten can already dump backtraces when run with RUST_BACKTRACE=1 wasmtime .... I need something like that, but for wasm32-unknown-unknown target.
Hmm, maybe I'm confused. In the two stack traces shown above, the first one is Rust stack trace. The second one is wasmtime. So Rust backtrace is dumped even without RUST_BACKTRACE=1. I'm guessing that means it's not Rust runtime/core/std that prints the backtrace, but wasmtime.
Also, without WASI a Wasm program can't print anything, so it doesn't make sense to expect a backtrace to be printed in wasm32-unknown-unknown program.
In the wasmtime example it is wasmtime itself that prints the wasm stack when an unreachable wasm trap occurs. Because the rust code is compiled to wasm, this is also the rust stack. When running in the browser, it would be the browser that attaches the combined wasm+javascript stack to the exception thrown when the wasm trap occurs.