Commit d8f95c4b authored by Ingvar Stepanyan's avatar Ingvar Stepanyan Committed by Commit Bot

[wasm] Prefer source map over DWARF info if present

Some tools that transform Wasm today, already support encoding the
transforms and correctly updating locations in source maps, but not yet
in DWARF (although this is being worked on).

Until they catch up, it's best to consistently prefer source maps over
DWARF when both are present, and not just rely on order of sections as
accidentally done in the previous CL that introduced DWARF info.

Ref: crrev.com/c/v8/v8/+/1834341
Bug: chromium:1016772
Change-Id: I769311e2096ae0e4ca304bef0a0453c7e0776aae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1888930
Commit-Queue: Ingvar Stepanyan <rreverser@google.com>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64647}
parent ba370876
...@@ -460,7 +460,10 @@ class ModuleDecoderImpl : public Decoder { ...@@ -460,7 +460,10 @@ class ModuleDecoderImpl : public Decoder {
DecodeSourceMappingURLSection(); DecodeSourceMappingURLSection();
break; break;
case kDebugInfoSectionCode: case kDebugInfoSectionCode:
// If there is an explicit source map, prefer it over DWARF info.
if (!has_seen_unordered_section(kSourceMappingURLSectionCode)) {
module_->source_map_url.assign("wasm://dwarf"); module_->source_map_url.assign("wasm://dwarf");
}
consume_bytes(static_cast<uint32_t>(end_ - start_), ".debug_info"); consume_bytes(static_cast<uint32_t>(end_ - start_), ".debug_info");
break; break;
case kCompilationHintsSectionCode: case kCompilationHintsSectionCode:
......
...@@ -4,8 +4,14 @@ Session #1: Script #0 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-0. So ...@@ -4,8 +4,14 @@ Session #1: Script #0 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-0. So
Session #1: Script #1 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-1. Source map URL: Session #1: Script #1 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-1. Source map URL:
Session #2: Script #0 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-0. Source map URL: Session #2: Script #0 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-0. Source map URL:
Session #2: Script #1 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-1. Source map URL: Session #2: Script #1 parsed. URL: wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-1. Source map URL:
Session #1: Script #2 parsed. URL: wasm://wasm/wasm-ef526f5e. Source map URL: wasm://dwarf Session #1: Script #2 parsed. URL: wasm://wasm/wasm-74f86b7e. Source map URL: wasm://dwarf
Session #2: Script #2 parsed. URL: wasm://wasm/wasm-ef526f5e. Source map URL: wasm://dwarf Session #2: Script #2 parsed. URL: wasm://wasm/wasm-74f86b7e. Source map URL: wasm://dwarf
Session #1: Script #3 parsed. URL: wasm://wasm/wasm-3754e3fe. Source map URL: abc
Session #2: Script #3 parsed. URL: wasm://wasm/wasm-3754e3fe. Source map URL: abc
Session #1: Script #4 parsed. URL: wasm://wasm/wasm-2bd2e40e. Source map URL: abc
Session #2: Script #4 parsed. URL: wasm://wasm/wasm-2bd2e40e. Source map URL: abc
Session #1: Script #5 parsed. URL: wasm://wasm/wasm-f568e726. Source map URL: abc
Session #2: Script #5 parsed. URL: wasm://wasm/wasm-f568e726. Source map URL: abc
Session #1: Source for wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-0: Session #1: Source for wasm://wasm/wasm-f608ae1e/wasm-f608ae1e-0:
func $nopFunction func $nopFunction
nop nop
...@@ -32,11 +38,35 @@ func $main ...@@ -32,11 +38,35 @@ func $main
end end
end end
Session #1: Source for wasm://wasm/wasm-ef526f5e: Session #1: Source for wasm://wasm/wasm-74f86b7e:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 0c 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 11 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 01 02 03 04 05 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: [] Imports: []
Exports: [main: function] Exports: [main: function]
Session #2: Source for wasm://wasm/wasm-ef526f5e: Session #2: Source for wasm://wasm/wasm-74f86b7e:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 0c 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 11 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 01 02 03 04 05 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: []
Exports: [main: function]
Session #1: Source for wasm://wasm/wasm-3754e3fe:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 15 10 73 6f 75 72 63 65 4d 61 70 70 69 6e 67 55 52 4c 03 61 62 63 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: []
Exports: [main: function]
Session #2: Source for wasm://wasm/wasm-3754e3fe:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 15 10 73 6f 75 72 63 65 4d 61 70 70 69 6e 67 55 52 4c 03 61 62 63 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: []
Exports: [main: function]
Session #1: Source for wasm://wasm/wasm-2bd2e40e:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 11 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 01 02 03 04 05 00 15 10 73 6f 75 72 63 65 4d 61 70 70 69 6e 67 55 52 4c 03 61 62 63 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: []
Exports: [main: function]
Session #2: Source for wasm://wasm/wasm-2bd2e40e:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 11 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 01 02 03 04 05 00 15 10 73 6f 75 72 63 65 4d 61 70 70 69 6e 67 55 52 4c 03 61 62 63 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: []
Exports: [main: function]
Session #1: Source for wasm://wasm/wasm-f568e726:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 15 10 73 6f 75 72 63 65 4d 61 70 70 69 6e 67 55 52 4c 03 61 62 63 00 11 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 01 02 03 04 05 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: []
Exports: [main: function]
Session #2: Source for wasm://wasm/wasm-f568e726:
Raw: 00 61 73 6d 01 00 00 00 01 07 02 60 00 00 60 00 00 03 03 02 00 01 07 08 01 04 6d 61 69 6e 00 01 0a 0e 02 03 00 01 0b 08 00 02 40 41 02 1a 0b 0b 00 15 10 73 6f 75 72 63 65 4d 61 70 70 69 6e 67 55 52 4c 03 61 62 63 00 11 0b 2e 64 65 62 75 67 5f 69 6e 66 6f 01 02 03 04 05 00 1b 04 6e 61 6d 65 01 14 02 00 0b 6e 6f 70 46 75 6e 63 74 69 6f 6e 01 04 6d 61 69 6e
Imports: [] Imports: []
Exports: [main: function] Exports: [main: function]
...@@ -17,16 +17,18 @@ let sessions = [ ...@@ -17,16 +17,18 @@ let sessions = [
utils.load('test/mjsunit/wasm/wasm-module-builder.js'); utils.load('test/mjsunit/wasm/wasm-module-builder.js');
// Add two empty functions. Both should be registered as individual scripts at // Create module with given custom sections.
// module creation time. function createModule(...customSections) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction('nopFunction', kSig_v_v).addBody([kExprNop]); builder.addFunction('nopFunction', kSig_v_v).addBody([kExprNop]);
builder.addFunction('main', kSig_v_v) builder.addFunction('main', kSig_v_v)
.addBody([kExprBlock, kWasmStmt, kExprI32Const, 2, kExprDrop, kExprEnd]) .addBody([kExprBlock, kWasmStmt, kExprI32Const, 2, kExprDrop, kExprEnd])
.exportAs('main'); .exportAs('main');
var module_bytes = builder.toArray(); for (var { name, value } of customSections) {
builder.addCustomSection('.debug_info', []); builder.addCustomSection(name, value);
var module_bytes_with_dwarf = builder.toArray(); }
return builder.toArray();
}
function testFunction(bytes) { function testFunction(bytes) {
// Compilation triggers registration of wasm scripts. // Compilation triggers registration of wasm scripts.
...@@ -34,16 +36,37 @@ function testFunction(bytes) { ...@@ -34,16 +36,37 @@ function testFunction(bytes) {
} }
contextGroup.addScript(testFunction.toString(), 0, 0, 'v8://test/testFunction'); contextGroup.addScript(testFunction.toString(), 0, 0, 'v8://test/testFunction');
contextGroup.addScript('var module_bytes = ' + JSON.stringify(module_bytes));
contextGroup.addScript('var module_bytes_with_dwarf = ' + JSON.stringify(module_bytes_with_dwarf));
InspectorTest.log( InspectorTest.log(
'Check that each inspector gets two wasm scripts at module creation time.'); 'Check that each inspector gets two wasm scripts at module creation time.');
// Sample .debug_info section.
// Content doesn't matter, as we don't try to parse it in V8,
// but should be non-empty to check that we're skipping it correctly.
const dwarfSection = { name: '.debug_info', value: [1, 2, 3, 4, 5] };
// Sample sourceMappingURL section set to "abc".
const sourceMapSection = { name: 'sourceMappingURL', value: [3, 97, 98, 99] };
sessions[0].Protocol.Runtime sessions[0].Protocol.Runtime
.evaluate({ .evaluate({
'expression': '//# sourceURL=v8://test/runTestRunction\n' + 'expression': `//# sourceURL=v8://test/runTestRunction
'testFunction(module_bytes); testFunction(module_bytes_with_dwarf);'
// no debug info
testFunction([${createModule()}]);
// DWARF
testFunction([${createModule(dwarfSection)}]);
// Source map
testFunction([${createModule(sourceMapSection)}]);
// DWARF + source map
testFunction([${createModule(dwarfSection, sourceMapSection)}]);
// Source map + DWARF (different order)
testFunction([${createModule(sourceMapSection, dwarfSection)}]);
`
}) })
.then(() => ( .then(() => (
// At this point all scripts were parsed. // At this point all scripts were parsed.
...@@ -89,7 +112,7 @@ function trackScripts(debuggerParams) { ...@@ -89,7 +112,7 @@ function trackScripts(debuggerParams) {
async function loadScript({url, scriptId, sourceMapURL}) { async function loadScript({url, scriptId, sourceMapURL}) {
InspectorTest.log(`Session #${sessionId}: Script #${scripts.length} parsed. URL: ${url}. Source map URL: ${sourceMapURL}`); InspectorTest.log(`Session #${sessionId}: Script #${scripts.length} parsed. URL: ${url}. Source map URL: ${sourceMapURL}`);
let scriptSource; let scriptSource;
if (sourceMapURL === "wasm://dwarf") { if (sourceMapURL) {
let {result: {bytecode}} = await Protocol.Debugger.getWasmBytecode({scriptId}); let {result: {bytecode}} = await Protocol.Debugger.getWasmBytecode({scriptId});
// Binary value is represented as base64 in JSON, decode it. // Binary value is represented as base64 in JSON, decode it.
bytecode = decodeBase64(bytecode); bytecode = decodeBase64(bytecode);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment