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:

https://github.com/emscripten-core/emscripten/blob/incoming/system/lib/libc/musl/src/stdio/fflush.c

The Javascript parts are here:

https://github.com/emscripten-core/emscripten/tree/incoming/src

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

https://github.com/emscripten-core/emscripten/tree/incoming/system/lib/gl

https://github.com/emscripten-core/emscripten/blob/incoming/src/library_webgl.js

https://github.com/emscripten-core/emscripten/blob/incoming/src/library_webgl2.js





On Monday, 22 July 2019 05:21:29 UTC+2, João Abelardo wrote:
>
> 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.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/2a714f2a-de31-4eca-a154-be9a95021160%40googlegroups.com.

Reply via email to