OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --expose-wasm |
| 6 |
| 7 load('test/mjsunit/wasm/wasm-constants.js'); |
| 8 load('test/mjsunit/wasm/wasm-module-builder.js'); |
| 9 |
| 10 var builder = new WasmModuleBuilder(); |
| 11 |
| 12 var imported_idx = builder.addImport("func", kSig_v_v); |
| 13 |
| 14 var call_imported_idx = builder.addFunction("call_func", kSig_v_v) |
| 15 .addBody([kExprCallFunction, imported_idx]) |
| 16 .index; |
| 17 |
| 18 var sig_index = builder.addType(kSig_v_v); |
| 19 |
| 20 builder.addFunction('main', kSig_v_v) |
| 21 .addBody([ |
| 22 kExprBlock, kAstStmt, kExprI32Const, 0, kExprCallIndirect, sig_index, |
| 23 kTableZero, kExprEnd |
| 24 ]) |
| 25 .exportAs('main'); |
| 26 |
| 27 builder.appendToTable([call_imported_idx]); |
| 28 |
| 29 var module_bytes = builder.toArray(); |
| 30 |
| 31 function testFunction(bytes) { |
| 32 function call_debugger() { |
| 33 debugger; |
| 34 } |
| 35 |
| 36 var buffer = new ArrayBuffer(bytes.length); |
| 37 var view = new Uint8Array(buffer); |
| 38 for (var i = 0; i < bytes.length; i++) { |
| 39 view[i] = bytes[i] | 0; |
| 40 } |
| 41 |
| 42 var module = new WebAssembly.Module(buffer); |
| 43 var instance = new WebAssembly.Instance(module, {func: call_debugger}); |
| 44 |
| 45 instance.exports.main(); |
| 46 } |
| 47 |
| 48 InspectorTest.addScript(testFunction.toString()); |
| 49 InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes)); |
| 50 |
| 51 Protocol.Debugger.enable(); |
| 52 Protocol.Debugger.onPaused(handleDebuggerPaused); |
| 53 InspectorTest.log('Check that inspector gets disassembled wasm code'); |
| 54 Protocol.Runtime.evaluate({'expression': 'testFunction(module_bytes)'}); |
| 55 |
| 56 function handleDebuggerPaused(message) { |
| 57 InspectorTest.log('Paused on debugger!'); |
| 58 var frames = message.params.callFrames; |
| 59 InspectorTest.log('Number of frames: ' + frames.length); |
| 60 function dumpSourceLine(frameId, sourceMessage) { |
| 61 if (sourceMessage.error) InspectorTest.logObject(sourceMessage); |
| 62 var text = sourceMessage.result.scriptSource; |
| 63 var lineNr = frames[frameId].location.lineNumber; |
| 64 var line = text.split('\n')[lineNr]; |
| 65 InspectorTest.log('[' + frameId + '] ' + line); |
| 66 } |
| 67 function next(frameId) { |
| 68 if (frameId == frames.length) return Promise.resolve(); |
| 69 return Protocol.Debugger |
| 70 .getScriptSource({scriptId: frames[frameId].location.scriptId}) |
| 71 .then(dumpSourceLine.bind(null, frameId)) |
| 72 .then(() => next(frameId + 1)); |
| 73 } |
| 74 function finished() { |
| 75 InspectorTest.log('Finished.'); |
| 76 InspectorTest.completeTest(); |
| 77 } |
| 78 next(0).then(finished); |
| 79 } |
OLD | NEW |