wabt icon indicating copy to clipboard operation
wabt copied to clipboard

Source maps for wasm2c?

Open SoniEx2 opened this issue 2 years ago • 6 comments

Does it... make any sense to have source maps for wasm2c?

SoniEx2 avatar Apr 25 '23 18:04 SoniEx2

It would be nice to have something like this, because it's pretty challenging to debug a program that's been compiled from, e.g., C++ (via g++) to Wasm (and then, via wasm2c) to C (and then, via gcc) to ELF. See #1210 & #432.

An MVP might be to make wasm2c include little comments next to each line of a function body, giving a Wat version of the Wasm instruction, so that if you then compile wasm2c's output with -g, a debugger that speaks DWARF can show the Wat for each line. That seems like a one-day project.

But it would be really nice to plumb it all the way through somehow so that a debugger of the final object file can show the original high-level source code.

keithw avatar Apr 25 '23 18:04 keithw

I think we could use C pre-processor directives: https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html

sbc100 avatar Apr 25 '23 18:04 sbc100

yup, the C-preprocessor debug directives was something I was hoping to do for several months now, but I don't think I have time on my roadmap. I would love to see support for something like this too!

shravanrn avatar Apr 27 '23 17:04 shravanrn

In w2c2 we parse the DWARF debug info (if provided) from the module, and generate C #line directives. It works fairly well

turbolent avatar May 27 '23 17:05 turbolent

(Sorry for the delay in responding was traveling) Ah this is good to know. I will add it to my todo list to see if we can get something like this as well. Assuming the licenses are compatible, and there are no objections, I am hoping we can borrow some of the implementation from w2c2 for this effort.

shravanrn avatar Jun 15 '23 13:06 shravanrn