leaningtech / cheerp-meta

Cheerp - a C/C++ compiler for Web applications - compiles to WebAssembly and JavaScript
https://labs.leaningtech.com/cheerp
Other
1.02k stars 49 forks source link

Is it possible to produce wasm with debug information? #123

Open monkbai opened 2 years ago

monkbai commented 2 years ago

Is it possible to produce wasm code with dwarf debug information attached? I have tried with /opt/cheerp/bin/clang++ -target cheerp-wasm test.c -o test14.js -O0 -g But the generated wasm code still contains no debug information.

carlopi commented 2 years ago

HI @monkbai!

The closest you could get is using:

-g -cheerp-sourcemap=test.js.map -cheerp-linear-output=asmjs

-g allows to pass debug information -cheerp-sourcemap=somefile generates a file with a given name that holds sourcemap information (for the devtools to be found) and -cheerp-linear-output=asmjs swtiches from the default wasm to asmjs-based generation for linear memory code, since currently Cheerp doesn't support Wasm-level source maps

Would this set-up work for you?

monkbai commented 2 years ago

Thank you @carlopi for answering. The asmjs code compiled with "-g" option is still hard to understand. Also, we prefer to compile wasm code for better performance. So sorry, this setup does not work. Do you have any plan to support attaching dwarf debug information on compiled wasm code? Just like what Emscripten "-g" option does?

Again, thank you for your advice.

carlopi commented 2 years ago

Producing source map for WebAssembly output it's doable and potentially useful, but currently it's not on the road map for the upcoming months.

To read asmjs code (or even WebAssembly-compiled code) it's beneficial to also add -cheerp-pretty-code, that keeps the variables name somehow more readable (even though there is no guarantee that a mapping between original variables and compiled variables has to be trivial).

Can I ask you what is the project you are working on? I would expect asmjs penality to be at worst 2x, and for debug builds (you are considering -O0) it's usually doable in exchange for easier inspectability (eg. it's easier to directly add debug statements JS side), while then deploying WebAssembly builds with higher optimizations enabled.

monkbai commented 2 years ago

Thank you very much for your help. We only use -O0 option to investigate the availability of dwarf debug information. We will consider turning to asmjs as well. Thanks!