How to debug/understand JS code generated from LLVM bytecode

22 views
Skip to first unread message

João Abelardo

unread,
Jul 21, 2019, 11:21:29 PM7/21/19
to emscripten-discuss
Hello, I am trying to fix an open issue on emscripten, but to do this first I need to understand how free and fflush are generated and works.

I already compiled the buggy code with -s WASM=0, so that all the code is in the JS file, the problem is that _free and _fflush functions are unreadable, it is full of non-sense variable names (I know it makes sense to be this way).

How can I understand how this functions are implemented, how they manage FS system in the JS and how they free the memory in JS, I mean the memory that emscripten simulates.

I know that this may be a ridiculous question, but I just could not found a material that could help me. A documentation explaining what is each part of the project and how the overall emscripten works "in depth" would be nice.

Thanks in advance.

J Decker

unread,
Jul 22, 2019, 12:05:10 AM7/22/19
to emscripten-discuss
-g  helps too

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/5d39fc82-65b0-4da5-8e60-2508361ed3cd%40googlegroups.com.

Floh

unread,
Jul 22, 2019, 7:15:20 AM7/22/19
to emscripten-discuss
It depends on whether the general area you want to debug was originally C code or Javascript code before it was compiled to asm.js/wasm (from C) and minified JS (from unminfied JS).

If the code was originally Javascript, you can get a non-minified version by compiling without optimizations and the (optional) closure-minifier pass, and (not sure about this) enable debug information with -g.

If the code was originally C or C++, your mostly out of luck, no matter whether this is translated to WASM or asm.js, both will be pretty much unreadable since it has first been compiled down to LLVM bitcode, and then translated to WASM or asm.js, so you lose the high-level program structure. Trying to read WASM or asm.js is both pretty much like trying to understand the high-level code structure from reading assembly code. Possible, but not much fun ;)

If I want to understand how code in emscripten's "system layer" works I usually look directly at the original source code:

emscripten's libc (a slightly modified musl) implementation is here: https://github.com/emscripten-core/emscripten/tree/incoming/system/lib/libc

For instance for understanding fflush() I would start looking here:


The Javascript parts are here:


Some libraries (like WebGL) are half C, half Javascript, e.g.:



Reply all
Reply to author
Forward
0 new messages