-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcemap support for wat2wasm? #1210
Comments
Just as a status:
Source maps assumes that only source code line information/mapping is present. But for efficient debugging, the original source types and locals metadata much be present. |
I've only recently begun looking through the WABT code. There may be something I don't understand here. If that is the case, I apologize for my ignorance. It doesn't look to me like wat2wasm in WABT uses binaryen. My thought is that wat2wasm could generate the sourcemap at the same time as the binary. If a flag is passed into wat2wasm, a structure would need to track the opcode bytes and the line/column they correspond to within the WAT file. It could then generate the sourcemap file from this data when the binary is complete and add the //#sourcemap= tag at the end of the binary that ties the sourcemap file to the wasm binary. I'm working on a prototype modification to WABT right now. Am I way off base on this? Is this less simple a change than I am imagining? Please let me know if there is some reason it can't be done like this. Thanks |
Generally source maps would be used to map from some other source language: e.g. C++, rust, etc. There's no standardized way to specify this information in the WebAssembly text format, so the best you can do when disassembling is include this information as a comment in the .wat file. Similarly, if you wanted to include arbitrary source map information in the text file, there's no standardized way to do that either. AIUI, binaryen uses a special comment format for this, but IMO it would be better to use an annotation, though those aren't standardized yet. OTOH, what you're describing is creating a sourcemap for the wat file itself, which shouldn't be too hard. This isn't all that useful for most users, since they won't be writing wat. But I think it still would be a useful feature, as long as that sourcemap information can be overridden when (or if?) we eventually get support for that. |
I am talking about a WAT sourcemap because disassembling the WAT code loses variable names and things like that. I know that the majority of users will not be writing code directly in WAT, but I feel like understanding WAT is beneficial for understanding WebAssembly in general. I will work on adding sourcemaps to wat2wasm if no one has any objection to that. |
@battlelinegames - I'd appreciate sourcemap support, and personally do write WAT code by hand. There are good reasons for using WAT as a first-class language in educational and hobby contexts. Even though it'll be a small percentage of users that use WAT directly, it may still get a lot of use in absolute terms. |
When you're writing a compiler, it could be convenient to use the browser to debug the generated code. Here, having the ability to see all the names that you deliberately placed in the generated
Does that mean there are undocumented ways? |
A discussion about adding sourcemap support came up on twitter. There's an old PR (#432), that could be revived, but we may want to approach this differently now. @dschuff @sbc100 thoughts?
The text was updated successfully, but these errors were encountered: