The note was conceived as a continuation of the previous note on how to build C ++ crashes on various platforms, including asm.js and wasm. By the amount of material, it pulls only a note, not a full-fledged article, and you have to be a drug addict, what would a native C ++ client do, and then shove it into a browser.
But! We recently reported on the experience of using wasm on cppconf . It turned out that there are more drug addicts than I thought, and the news Beta for Qt for WebAssembly Technology Preview . This note can be useful if you want to capture kreshy in the production environment.
Under the cut:
Capture occurs through the global window.onerror handler.
window.onerror = function(messageOrEvent, source, lineno, colno, error) { ... }
In asm.js , the error message and the call stack are passed in the messageOrEvent
parameter. In the case of wasm in a messageOrEvent
reason, something like Error: Out of bounds memory access (evaluating 'dynCall(rawFunction, a1, a2, a3)')
, RuntimeError: index out of bounds
, etc.
And the error
gets a stack of calls.
We use the - --emit-symbol-map
key when compiling, which minimizes the names of functions. After compilation we get the so-called symbol files.
This is the symbol file for asm.js:
ljd:___cxx_global_array_dtor_11639 YZb:___cxx_global_array_dtor_40_30909 Ya:_glClearStencil
For wasm, this is the function number and the function name:
14:_glStencilFunc 15:_glUniformMatrix4fv 16:_emscripten_set_touchend_callback 17:_glGenRenderbuffers 18:_emscripten_set_webglcontextlost_callback 19:_glUniform2fv
The stack in different browsers looks different
Safari:
wasm function: 5960@[wasm code] wasm function: 5984@[wasm code] wasm function: 5981@[wasm code] wasm function: 1233@[wasm code] wasm function: 1232@[wasm code] wasm function: 34895@[wasm code] wasm function@[wasm code] dynCall_viii@[native code]
Firefox:
wasm-function[5960]@https://path_to_source wasm-function[5984]@https://path_to_source wasm-function[5981]@https://path_to_source wasm-function[1233]@https://path_to_source wasm-function[1232]@https://path_to_source wasm-function[34895]@https://path_to_source dynCall_viii_419@https://path_to_source
Chrome:
at wasm-function[2007]:11 at wasm-function[11257]:228 at wasm-function[11606]:479 at wasm-function[11604]:1726 at wasm-function[11819]:91 at wasm-function[9055]:274 at wasm-function[9052]:26 at wasm-function[2721]:92 at wasm-function[1302]:2523 at wasm-function[4946]:69
Chrome gives not only the function number 2007 , but also an offset of 11 in it. Also chrome allows you to view the code in text form. The screenshot shows the function code 276.
This is useful, for example, if you fired an undefined behavior .
It remains only to pull out the numbers of the functions, compare them with the functions in the file, skip through abi::__cxa_demangle
, in order to get a readable call stack.
Source: https://habr.com/ru/post/343784/
All Articles