- Home /
Can Unity export the Emscripten symbols map on WebGL builds?
I am looking to get a stack trace on crashes for minified RELEASE builds in WebGL, and believe we can do this using the standard Emscripten output, as we have done it on another project that uses Emscripten. I know that you can get a readable stack trace on DEBUG builds because of the following:
When you tick the “Development Build” checkbox, Unity will generate a development build (with Profiler support and the development console for errors, like on other platforms). Additionally, Development builds are non-minified, so the generated JavaScript is human-readable and preserves function names (so you will get useful stack traces for errors), but very large to distribute.
http://docs.unity3d.com/Manual/webgl-building.html
What we need is a specific symbol to be added to the build args for emscripten, --emit-symbol-map, so that the file is outputted in the build. From the emscripten docs:
--emit-symbol-map: Save a map file between the minified global names and the original function names. This allows you, for example, to reconstruct meaningful stack traces.
https://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html
That is the file we get on our other project where we can see the symbols map.
Unity seems to have its own method of passing arguments to emscripten. For example, when you select the "Optimizations Level" in the WebGL settings, it modifies an entry to the projectsettings.asset. At compile time, that entry is mapped to the optimization argument passed into emscripten, for example, "Fast Builds" in Unity maps to -O0: no optimizations. One of the others maps to -O2: various JavaScript-level optimizations and LLVM -03 optimizations.
The problem is, as far as I know, there isn't a place where we can inject custom args into the emscripten execution. We need this argument to be passed to emscripten, and the resulting .symbols file to end up in the build output folder. Then we can read the Javascript stack trace, hand-map it to the cpp stack trace, and finally to our C# code, which will be very useful for crash debugging.
Can this be done in Unity as is?
Answer by Marco-Trivellato · May 03, 2016 at 10:11 AM
In Unity 5.4+, we internally pass --emit-symbol-map to emcc.
In Unity 5.0-5.3, we don't but you can do that via editor scripting:
PlayerSettings.SetPropertyString("emscriptenArgs", "--emit-symbol-map");
hope that helps!
Is it possible to have unity tell emscipten to compile for WebAssembly as in this post: https://hacks.mozilla.org/2015/12/compiling-to-webassembly-its-happening/
emcc file.cpp -o file.js -s ‘BINARYEN=”path-to-binaryen”’
$$anonymous$$arked as obsolete in 2017.4, how do we do this now?
Answer by DAVco · Oct 05, 2018 at 09:52 AM
Just to update the answer for Unity 2017+
PlayerSettings.SetPropertyString is deprecated and we should use the following instead:
PlayerSettings.WebGL.emscriptenArgs = "your args"
Your answer
Follow this Question
Related Questions
WebGL Lags and Arrow Keys do not work 0 Answers
How to use Webgl Debug Symbols? 0 Answers
How do you show C# line numbers in a WebGL build's stack trace? 1 Answer
How do you do repeated "Build & Run" builds with WebGL without recompiling? 0 Answers
How to debug a maximum call stack size error in WebGL? 0 Answers