-
Notifications
You must be signed in to change notification settings - Fork 745
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
Exporting/importing debug location information from .wast/.asm.js/.s formats #1017
Changes from all commits
19b2ea5
da4f615
9fcdc20
f7bd8c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,31 @@ def do_asm2wasm_test(): | |
fail_with_error('wasm interpreter error: ' + err) # failed to pretty-print | ||
fail_with_error('wasm interpreter error') | ||
|
||
# verify debug info | ||
if 'debugInfo' in asm: | ||
jsmap = 'a.wasm.map' | ||
cmd += ['--source-map', jsmap, | ||
'--source-map-url', 'http://example.org/' + jsmap, | ||
'-o', 'a.wasm'] | ||
run_command(cmd) | ||
if not os.path.isfile(jsmap): | ||
fail_with_error('Debug info map not created: %s' % jsmap) | ||
with open(wasm + '.map', 'rb') as expected: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like this uses some new test output files in the test dir. please also update |
||
with open(jsmap, 'rb') as actual: | ||
fail_if_not_identical(actual.read(), expected.read()) | ||
with open('a.wasm', 'rb') as binary: | ||
url_section_name = bytearray([16]) + bytearray('sourceMappingURL') | ||
payload = 'http://example.org/' + jsmap | ||
assert len(payload) < 256, 'name too long' | ||
url_section_contents = bytearray([len(payload)]) + bytearray(payload) | ||
print url_section_name | ||
binary_contents = bytearray(binary.read()) | ||
if url_section_name not in binary_contents: | ||
fail_with_error('source map url section not found in binary') | ||
if url_section_contents not in binary_contents[binary_contents.index(url_section_name):]: | ||
fail_with_error('source map url not found in url section') | ||
|
||
|
||
print '\n[ checking asm2wasm binary reading/writing... ]\n' | ||
|
||
asmjs = os.path.join(options.binaryen_test, 'hello_world.asm.js') | ||
|
@@ -241,6 +266,8 @@ def do_asm2wasm_test(): | |
print '..', t | ||
t = os.path.join(options.binaryen_test, t) | ||
cmd = WASM_DIS + [t] | ||
if os.path.isfile(t + '.map'): cmd += ['--source-map', t + '.map'] | ||
|
||
actual = run_command(cmd) | ||
|
||
with open(t + '.fromBinary') as f: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ using namespace wasm; | |
int main(int argc, const char *argv[]) { | ||
bool debugInfo = false; | ||
std::string symbolMap; | ||
std::string sourceMapFilename; | ||
std::string sourceMapUrl; | ||
Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)"); | ||
options.extra["validate"] = "wasm"; | ||
options | ||
|
@@ -51,6 +53,12 @@ int main(int argc, const char *argv[]) { | |
.add("--debuginfo", "-g", "Emit names section and debug info", | ||
Options::Arguments::Zero, | ||
[&](Options *o, const std::string &arguments) { debugInfo = true; }) | ||
.add("--source-map", "-sm", "Emit source map to the specified file", | ||
Options::Arguments::One, | ||
[&sourceMapFilename](Options *o, const std::string &argument) { sourceMapFilename = argument; }) | ||
.add("--source-map-url", "-su", "Use specified string as source map URL", | ||
Options::Arguments::One, | ||
[&sourceMapUrl](Options *o, const std::string &argument) { sourceMapUrl = argument; }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are duplicated in two files. i am currently getting rid of most of the existing duplication in #1023. it would be good to do the same thing for these options, however, i understand if you want to land this first and leave the refactoring to followup work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather move this out of scope this PR -- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good point, we'll need more refactoring here. Definitely let's leave for later. |
||
.add("--symbolmap", "-s", "Emit a symbol map (indexes => names)", | ||
Options::Arguments::One, | ||
[&](Options *o, const std::string &argument) { symbolMap = argument; }) | ||
|
@@ -86,13 +94,23 @@ int main(int argc, const char *argv[]) { | |
if (options.debug) std::cerr << "binarification..." << std::endl; | ||
BufferWithRandomAccess buffer(options.debug); | ||
WasmBinaryWriter writer(&wasm, buffer, options.debug); | ||
writer.setDebugInfo(debugInfo); | ||
// if debug info is used, then we want to emit the names section | ||
writer.setNamesSection(debugInfo); | ||
std::unique_ptr<std::ofstream> sourceMapStream = nullptr; | ||
if (sourceMapFilename.size()) { | ||
sourceMapStream = make_unique<std::ofstream>(); | ||
sourceMapStream->open(sourceMapFilename); | ||
writer.setSourceMap(sourceMapStream.get(), sourceMapUrl); | ||
} | ||
if (symbolMap.size() > 0) writer.setSymbolMap(symbolMap); | ||
writer.write(); | ||
|
||
if (options.debug) std::cerr << "writing to output..." << std::endl; | ||
Output output(options.extra["output"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release); | ||
buffer.writeTo(output); | ||
if (sourceMapStream) { | ||
sourceMapStream->close(); | ||
} | ||
|
||
if (options.debug) std::cerr << "Done." << std::endl; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
a.wasm
the right place for this? it should be stored wherecheck.py
looks for it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code above generates proper data for test;
a.wasm
is just a file we can delete -- we only need source map from this run.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks. Sorry for my confusion.