Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: test/inspector/debugger/wasm-stepping.js

Issue 2651043004: [wasm] Add inspector test for stepping (Closed)
Patch Set: Add expected output Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/inspector/debugger/wasm-stepping.js
diff --git a/test/inspector/debugger/wasm-stepping.js b/test/inspector/debugger/wasm-stepping.js
new file mode 100644
index 0000000000000000000000000000000000000000..944e1c6031d5832be7bc1931b092851048c18d8f
--- /dev/null
+++ b/test/inspector/debugger/wasm-stepping.js
@@ -0,0 +1,179 @@
+// Copyright 2017 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.
+
+load('test/mjsunit/wasm/wasm-constants.js');
+load('test/mjsunit/wasm/wasm-module-builder.js');
+
+var builder = new WasmModuleBuilder();
+
+var func_a_idx =
+ builder.addFunction('wasm_A', kSig_v_v).addBody([kExprNop, kExprNop]).index;
+
+// wasm_B calls wasm_A <param0> times.
+builder.addFunction('wasm_B', kSig_v_i)
+ .addBody([
+ // clang-format off
+ kExprLoop, kWasmStmt, // while
+ kExprGetLocal, 0, // -
+ kExprIf, kWasmStmt, // if <param0> != 0
+ kExprGetLocal, 0, // -
+ kExprI32Const, 1, // -
+ kExprI32Sub, // -
+ kExprSetLocal, 0, // decrease <param0>
+ kExprCallFunction, func_a_idx, // -
+ kExprBr, 1, // continue
+ kExprEnd, // -
+ kExprEnd, // break
+ // clang-format on
+ ])
+ .exportAs('main');
+
+var module_bytes = builder.toArray();
+
+function instantiate(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);
+ // Set global variable.
+ instance = new WebAssembly.Instance(module);
+}
+
+var addSourceUrl = (code, url) => '//# sourceURL=' + url + '\n' + code;
+
+function evalThen(expr, url, next) {
+ var promise = Protocol.Runtime.evaluate(
+ {'expression': addSourceUrl(expr, 'v8://test/' + url)});
+ if (next) promise = promise.then(next);
+ return promise;
+}
+
+Protocol.Debugger.onScriptParsed(handleScriptParsed);
+Protocol.Debugger.onPaused(handlePaused);
+var wasm_B_scriptId;
+var step_actions = [
+ 'stepInto', // == stepOver, to call instruction
+ 'stepInto', // into call to wasm_A
+ 'stepOver', // over first nop
+ 'stepOut', // out of wasm_A
+ 'stepOut', // out of wasm_B, stop on breakpoint again
+ 'stepOver', // to call
+ 'stepOver', // over call
+ 'resume', // to next breakpoint (third iteration)
+ 'stepInto', // to call
+ 'stepInto', // into wasm_A
+ 'stepOut', // out to wasm_B
+ // now step 9 times, until we are in wasm_A again.
+ 'stepInto', 'stepInto', 'stepInto', 'stepInto', 'stepInto', 'stepInto',
+ 'stepInto', 'stepInto', 'stepInto',
+ // 3 more times, back to wasm_B.
+ 'stepInto', 'stepInto', 'stepInto',
+ // then just resume.
+ 'resume'
+];
+var sources = {};
+var urls = {};
+var afterTwoSourcesCallback;
+
+InspectorTest.runTestSuite([
+ function enableDebugger(next) {
+ Protocol.Debugger.enable().then(next);
+ },
+
+ function defineInstance(next) {
+ evalThen('var instance;', 'defineInstance', next);
+ },
+
+ function defineInstantiateFunction(next) {
+ evalThen(instantiate.toString(), 'defineInstantiateFunction', next);
+ },
+
+ function callInstantiate(next) {
+ afterTwoSourcesCallback = next;
+ evalThen(
+ 'instantiate(' + JSON.stringify(module_bytes) + ')', 'callInstantiate');
+ },
+
+ function setBreakpoint(next) {
+ if (!wasm_B_scriptId) {
+ InspectorTest.log('Missing wasm_B script id');
+ }
+ InspectorTest.log(
+ 'Setting breakpoint on line 7 (on the setlocal before the call)');
+ Protocol.Debugger
+ .setBreakpoint(
+ {'location': {'scriptId': wasm_B_scriptId, 'lineNumber': 7}})
+ .then(msg => InspectorTest.logMessage(msg))
+ .then(next);
+ },
+
+ function runTestFunction(next) {
+ evalThen('instance.exports.main(4)', 'runWasm')
+ .then(() => InspectorTest.log('exports.main returned!'))
+ .then(next);
+ },
+
+ function finished(next) {
+ InspectorTest.log('Finished!');
+ next();
+ }
+]);
+
+function getSourceFromMessage(message) {
+ if (!message.result || !message.result.scriptSource) {
+ InspectorTest.logMessage(message);
+ return '';
+ }
+ return message.result.scriptSource;
+}
+
+function handleScriptParsed(msg) {
+ var url = msg.params.url;
+ if (!url.startsWith('wasm://')) {
+ InspectorTest.log('Ignoring script with url ' + url);
+ return;
+ }
+ var scriptId = msg.params.scriptId;
+ urls[scriptId] = url;
+ InspectorTest.log('Got wasm script: ' + url);
+ if (url.substr(-2) == '-1') wasm_B_scriptId = scriptId;
+ InspectorTest.log('Requesting source...');
+ function printAndStoreSource(src) {
+ InspectorTest.log(src);
+ sources[scriptId] = src;
+ if (Object.keys(sources).length == 2) afterTwoSourcesCallback();
+ }
+
+ Protocol.Debugger.getScriptSource({scriptId: scriptId})
+ .then(msg => printAndStoreSource(getSourceFromMessage(msg)));
+}
+
+function printPauseLocation(scriptId, lineNr, columnNr) {
+ var lines = sources[scriptId].split('\n');
+ var line = '<illegal line number>';
+ if (lineNr < lines.length) {
+ line = lines[lineNr];
+ if (columnNr < line.length) {
+ line = line.substr(0, columnNr) + '>' + line.substr(columnNr);
+ }
+ }
+ InspectorTest.log(
+ 'Paused at ' + urls[scriptId] + ':' + lineNr + ':' + columnNr + ': ' +
+ line);
+}
+
+function handlePaused(msg) {
+ var loc = msg.params.callFrames[0].location;
+ printPauseLocation(loc.scriptId, loc.lineNumber, loc.columnNumber);
+ var action = step_actions.shift();
+ InspectorTest.log('Step action: ' + action);
+ if (!action) {
+ InspectorTest.log('Undefined step action! Assuming resume.');
+ action = 'resume';
+ }
+ Protocol.Debugger[action]();
+}

Powered by Google App Engine
This is Rietveld 408576698