Chromium Code Reviews| Index: test/inspector/debugger/wasm-get-breakable-locations.js |
| diff --git a/test/inspector/debugger/wasm-get-breakable-locations.js b/test/inspector/debugger/wasm-get-breakable-locations.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e9448ff1af7c3d1301c9c15c381ad0418d1bd2f |
| --- /dev/null |
| +++ b/test/inspector/debugger/wasm-get-breakable-locations.js |
| @@ -0,0 +1,149 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --expose-wasm |
| + |
| +load('test/mjsunit/wasm/wasm-constants.js'); |
| +load('test/mjsunit/wasm/wasm-module-builder.js'); |
| + |
| +var builder = new WasmModuleBuilder(); |
| + |
| +// clang-format off |
| +var func_idx = builder.addFunction('helper', kSig_v_v) |
| + .addLocals({i32_count: 1}) |
| + .addBody([ |
| + kExprNop, |
| + kExprI32Const, 12, |
| + kExprSetLocal, 0, |
| + ]).index; |
| + |
| +builder.addFunction('main', kSig_v_i) |
| + .addBody([ |
| + kExprGetLocal, 0, |
| + kExprIf, kWasmStmt, |
| + kExprBlock, kWasmStmt, |
| + kExprCallFunction, func_idx, |
| + kExprEnd, |
| + kExprEnd |
| + ]).exportAs('main'); |
| +// clang-format on |
| + |
| +var module_bytes = builder.toArray(); |
| + |
| +function testFunction(bytes) { |
| + var buffer = new ArrayBuffer(bytes.length); |
| + var view = new Uint8Array(buffer); |
| + for (var i = 0; i < bytes.length; i++) { |
| + view[i] = bytes[i] | 0; |
| + } |
| + |
| + var module = new WebAssembly.Module(buffer); |
| +} |
| + |
| +var addSourceUrl = (code, url) => '//# sourceURL=' + url + '\n' + code; |
| + |
| +InspectorTest.addScript( |
| + addSourceUrl(testFunction.toString(), 'v8://test/testFunction')); |
| +InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes)); |
| + |
| +Protocol.Debugger.enable(); |
| +Protocol.Debugger.onScriptParsed(handleScriptParsed); |
| +InspectorTest.log('Running testFunction...'); |
| +Protocol.Runtime |
| + .evaluate({ |
| + 'expression': addSourceUrl( |
| + 'testFunction(module_bytes)', 'v8://test/runTestFunction') |
| + }) |
| + .then(getBreakableLocationsForAllWasmScripts) |
| + .then(() => InspectorTest.log('Finished!')) |
| + .then(InspectorTest.completeTest); |
| + |
| +var numScripts = 0; |
| +var wasmScripts = []; |
| +function handleScriptParsed(messageObject) { |
| + var scriptId = messageObject.params.scriptId; |
| + var url = messageObject.params.url; |
| + InspectorTest.log('Script nr ' + numScripts + ' parsed. URL: ' + url); |
| + ++numScripts; |
| + |
| + if (url.startsWith('wasm://')) { |
| + InspectorTest.log('This is a wasm script (nr ' + wasmScripts.length + ').'); |
| + wasmScripts.push(scriptId); |
| + } |
| +} |
| + |
| +function printBreakableLocations(message, expectedScriptId, source) { |
| + if (!message.result || !message.result.locations) { |
| + InspectorTest.logMessage(message); |
| + return; |
| + } |
| + var lines = source.split('\n'); |
| + var locations = message.result.locations; |
| + InspectorTest.log(locations.length + ' breakable location(s):'); |
| + for (var i = 0; i < locations.length; ++i) { |
| + if (locations[i].scriptId != expectedScriptId) { |
| + InspectorTest.log( |
| + 'SCRIPT ID MISMATCH!! ' + locations[i].scriptId + ' != ' + |
| + expectedScriptId); |
| + } |
| + var line = '<illegal line number>'; |
| + if (locations[i].lineNumber < lines.length) { |
| + line = lines[locations[i].lineNumber]; |
| + if (locations[i].columnNumber < line.length) { |
| + line = line.substr(0, locations[i].columnNumber) + '>' + |
| + line.substr(locations[i].columnNumber); |
| + } |
| + } |
| + InspectorTest.log( |
| + '[' + i + '] ' + locations[i].lineNumber + ':' + |
| + locations[i].columnNumber + ' || ' + line); |
| + } |
| +} |
| + |
| +function getSourceFromMessage(message) { |
| + if (!message.result || !message.result.scriptSource) { |
|
kozy
2017/01/25 18:34:19
Why do you need this method? If you have only vali
Clemens Hammacher
2017/01/25 20:23:54
I thought it helps debugging in the error case. Re
|
| + InspectorTest.logMessage(message); |
| + return ''; |
| + } |
| + return message.result.scriptSource; |
| +} |
| + |
| +function checkGetBreakableLocations(wasmScriptNr) { |
| + InspectorTest.log( |
| + 'Requesting all breakable locations in wasm script ' + wasmScriptNr); |
| + var scriptId = wasmScripts[wasmScriptNr]; |
| + var source; |
| + return Protocol.Debugger.getScriptSource({scriptId: scriptId}) |
| + .then((message) => source = getSourceFromMessage(message)) |
| + .then( |
| + () => Protocol.Debugger.getPossibleBreakpoints( |
| + {start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId}})) |
| + .then((message) => printBreakableLocations(message, scriptId, source)) |
| + .then( |
| + () => InspectorTest.log( |
| + 'Requesting breakable locations in lines [0,3)')) |
| + .then(() => Protocol.Debugger.getPossibleBreakpoints({ |
| + start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId}, |
| + end: {lineNumber: 3, columnNumber: 0, scriptId: scriptId} |
| + })) |
| + .then((message) => printBreakableLocations(message, scriptId, source)) |
| + .then( |
| + () => InspectorTest.log( |
| + 'Requesting breakable locations in lines [4,6)')) |
| + .then(() => Protocol.Debugger.getPossibleBreakpoints({ |
|
kozy
2017/01/25 18:34:19
Could we add following test:
getPossibleBreakpoint
Clemens Hammacher
2017/01/25 20:23:54
Fair enough :)
Added this test, moving over two fi
|
| + start: {lineNumber: 4, columnNumber: 0, scriptId: scriptId}, |
| + end: {lineNumber: 6, columnNumber: 0, scriptId: scriptId} |
| + })) |
| + .then((message) => printBreakableLocations(message, scriptId, source)); |
| +} |
| + |
| +function getBreakableLocationsForAllWasmScripts() { |
| + InspectorTest.log('Querying breakable locations for all wasm scripts now...'); |
| + var promise = Promise.resolve(); |
| + for (var wasmScriptNr = 0; wasmScriptNr < wasmScripts.length; |
| + ++wasmScriptNr) { |
| + promise = promise.then(checkGetBreakableLocations.bind(null, wasmScriptNr)); |
| + } |
| + return promise; |
| +} |