-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[EH] Stack trace support for Wasm EH #17466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think I can make this work for Wasm EH, but I'm not sure if the same is possible for Emscripten EH. If we throw a JS |
+1 for fixing only in Wasm EH. Even if people can't ship with it yet on all browsers, for local debugging a developer can use a recent browser with Wasm EH. |
This embeds stack traces into `WebAssembly.Exception` objects when `ASSERTION` is set. To do this, we now have a separate debug version of libc++abi, whose `__cxa_throw` doesn't call libunwind's `_Unwind_RaiseException`, which uses Wasm's `throw` instruction directly to throw exceptions, but rather calls out to a helper JS function that creates and throws `WebAssembly.Exception`. That JS function uses the optional `stack` property of `WebAssembly.Exception` constructor to attach stack traces to objects. Without `ASSERTION` set, when an exception is thrown and uncaught, we only see something like ``` exiting due to exception: [object WebAssembly.Exception] ``` And this is what we've seen so far as well. With this patch, when `ASSERTION` is set, we see stack traces like ``` exiting due to exception: [object WebAssembly.Exception],Error at ___throwCppWebAssemblyException (test.js:1139:13) at __cxa_throw (wasm://wasm/009a7c9a:wasm-function[1551]:0x24367) at bar() (wasm://wasm/009a7c9a:wasm-function[12]:0xf53) at foo() (wasm://wasm/009a7c9a:wasm-function[19]:0x154e) at __original_main (wasm://wasm/009a7c9a:wasm-function[20]:0x15a6) at main (wasm://wasm/009a7c9a:wasm-function[56]:0x25be) at test.js:833:22 at callMain (test.js:4567:15) at doRun (test.js:4621:23) at run (test.js:4636:5) ``` Fixes emscripten-core#17466.
This embeds stack traces into `WebAssembly.Exception` objects when `ASSERTIONS` is set. To do this, we now have a separate debug version of libc++abi, whose `__cxa_throw` doesn't call libunwind's `_Unwind_RaiseException`, which uses Wasm's `throw` instruction directly to throw exceptions, but rather calls out to a helper JS function that creates and throws `WebAssembly.Exception`. That JS function uses the optional `stack` property of `WebAssembly.Exception` constructor to attach stack traces to objects. Without `ASSERTIONS` set, when an exception is thrown and uncaught, we only see something like ``` exiting due to exception: [object WebAssembly.Exception] ``` And this is what we've seen so far as well. With this patch, when `ASSERTIONS` is set, we see stack traces like ``` exiting due to exception: [object WebAssembly.Exception],Error at __cxa_throw (wasm://wasm/009a7c9a:wasm-function[1551]:0x24367) at bar() (wasm://wasm/009a7c9a:wasm-function[12]:0xf53) at foo() (wasm://wasm/009a7c9a:wasm-function[19]:0x154e) at __original_main (wasm://wasm/009a7c9a:wasm-function[20]:0x15a6) at main (wasm://wasm/009a7c9a:wasm-function[56]:0x25be) at test.js:833:22 at callMain (test.js:4567:15) at doRun (test.js:4621:23) at run (test.js:4636:5) ``` Fixes #17466.
Currently, both in Emscripten and Wasm EH, if you throw an exception, stack traces are not attached by default. This was, at least for Wasm EH, an intentional decision, because Wasm exception itself can be used not only for errors but for other control flow structures with which slowdown can be problematic. Native C++ exceptions don't have stack traces either.
But it is still convenient to see stack traces when debugging. I think we can attach stack traces when in debug / assert mode, by throwing an
Error
object instead of a raw string in case of Emscripten EH, and turning the optionaltraceStack
option on in the JS API for Wasm EH.Related request: #17437
The text was updated successfully, but these errors were encountered: