binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Support for all optimization passes with DWARF output?

Open binji opened this issue 2 years ago • 5 comments

It seems as though there are still a few optimization passes that invalidate DWARF, so they are disabled when DWARF output is requested. Is there any plan to implement DWARF support for these passes? It would be useful to be able to generate DWARF output with a Release build and split DWARF so the debug symbols can be uploaded to Sentry (for example).

binji avatar Jul 19 '22 23:07 binji

We've been thinking about this, cc @dschuff @aheejin

IIUC the idea in Sentry is to get a proper stack trace from a crash?

For that use case, in principle a source map should be enough. Binaryen does have full support for source maps, so if we added a source map => DWARF tool that could work for Sentry. We have a DWARF => source map tool already (it's how we generate source maps actually), so I am hoping that other direction is not too difficult.

Inlining may reduce the quality of stack traces using source maps somewhat, but there are some ideas on how to improve that - we could emit inlining info in the DWARF, in fact, even if it's not there in the source maps, by using function mapping info (if source maps indicate the code is from function A, but it is actually function B, then necessarily A got inlined into B).

The other option would be full DWARF support in Binaryen. That's the only way to get additional things like mapping of local variables. That would be quite a lot of work, and it is why several passes are disabled atm. But for stack traces, that's not necessary.

My overall hope is that debug builds can skip Binaryen and use DWARF, for local debugging. And for uses of debug info in production, like stack traces, we can use source maps as above. I hope that covers the main use cases here, but it's possible I'm missing something.

kripken avatar Jul 20 '22 16:07 kripken

A source map would work for basic stack traces, though it would be nice to be able to support line numbers in the stack trace too. Local variables aren't as interesting for this use case, though, I agree.

binji avatar Jul 20 '22 18:07 binji

Oh sorry, I think I was confused. Source maps have line info, right? In that case I think a tool to convert from source maps to DWARF (or for Sentry to load source maps directly) would work.

binji avatar Jul 20 '22 18:07 binji

Yes, source maps have filename+line numbers. (maybe columns too? I'm not sure)

kripken avatar Jul 20 '22 18:07 kripken

Allowing conversion of SM -> DWARF seems like a good idea. I do think it would still be nice to eventually make it more seamless, e.g. automatically generate a DWARF line table for the output if the input had one. It would be an interesting question what to do if the input has full dwarf info (drop the non-line-table part? leave it incorrect? warn? error?).

dschuff avatar Jul 21 '22 23:07 dschuff