Backtrace using wasm


#1

is it possible? I’m specifically using emscripten and setting RUST_BACKTRACE=1 or full in preRun as advised here: https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html

but all i get when doing that is

Unwind_GetIPInfo

after the application panics.


#2

I have the same problem, and found this thread through a search. Anyone know of any possible fix to get Rust backtraces working with WebAssembly?

To be more explicit, I’m setting RUST_BACKTRACE=1 in my src/main.rs as follows:

fn main() {
    std::env::set_var("RUST_BACKTRACE", "1");

Then I build with the wasm32-unknown-emscripten target, and attempt to load my emscripten-built program in a browser. The terminal logs Unwind_GetIPInfo, though the JavaScript console has additional information:

shell.html:1246 thread 'main' panicked at 'assertion failed: validate_hidpi_factor(dpi_factor)', .cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.18.0/src/dpi.rs:236:9
printErr @ shell.html:1246
shell.html:1237 Unwind_GetIPInfo
shell.html:1246 Unwind_GetIPInfo
printErr @ shell.html:1246
shell.html:1246 warning: build with  -s DEMANGLE_SUPPORT=1  to link in libcxxabi demangling
printErr @ shell.html:1246
shell.html:1246 exception thrown: abort("Unwind_GetIPInfo") at Error
    at jsStackTrace (http://localhost:8000/target/wasm32-unknown-emscripten/debug/test.js:1106:13)
    at stackTrace (http://localhost:8000/target/wasm32-unknown-emscripten/debug/test.js:1123:12)
    at abort (http://localhost:8000/target/wasm32-unknown-emscripten/debug/test.js:11659:44)
    at __Unwind_GetIPInfo (http://localhost:8000/target/wasm32-unknown-emscripten/debug/test.js:6684:7)
    at __ZN3std3sys4unix9backtrace7tracing3imp8trace_fn17hc6f9b7d159d84b8eE_llvm_5A0A6270 (wasm-function[19973]:82)
    at dynCall_iii (wasm-function[20472]:16)
    at Object.Module.dynCall_iii (http://localhost:8000/target/wasm32-unknown-emscripten/debug/test.js:11402:92)
    at __Unwind_Backtrace (http://localhost:8000/target/wasm32-unknown-emscripten/debug/test.js:9861:40)
    at __ZN3std3sys4unix9backtrace7tracing3imp16unwind_backtrace17h4d215aadcaa52ebeE (wasm-function[19972]:63)
    at __ZN3std10sys_common9backtrace5print17h82720234d7357f67E (wasm-function[19812]:143)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

The message has two suggestions, building with -s ASSERTIONS=1 or -s DEMANGLE_SUPPORT=1. Presumably these are options to emcc. @arturo did you try these options? I’m not sure how to pass them to emscripten through cargo. Has anyone got this working?


#3

I haven’t tried the emscripten backend, but on wasm32-unknown-unknown, the console_error_panic_hook crate works quite nicely.