| 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 --expose-debug-as debug | |
| 6 | |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | |
| 9 | |
| 10 Debug = debug.Debug | |
| 11 | |
| 12 // Initialized in setup(). | |
| 13 var exception; | |
| 14 var break_count; | |
| 15 var num_wasm_scripts; | |
| 16 var module; | |
| 17 | |
| 18 function listener(event, exec_state, event_data, data) { | |
| 19 try { | |
| 20 if (event == Debug.DebugEvent.Break) { | |
| 21 ++break_count; | |
| 22 // Request frame details. This should trigger creation of the Script | |
| 23 // objects for all frames on the stack. | |
| 24 var num_frames = exec_state.frameCount(); | |
| 25 for (var i = 0; i < num_frames; ++i) { | |
| 26 var frame = exec_state.frame(i); | |
| 27 var details = frame.details(); | |
| 28 var script = details.script(); | |
| 29 if (script.type == Debug.ScriptType.Wasm) { | |
| 30 var pos = frame.sourcePosition(); | |
| 31 var name = script.nameOrSourceURL(); | |
| 32 var disassembly = Debug.disassembleWasmFunction(script.id); | |
| 33 var offset_table = Debug.getWasmFunctionOffsetTable(script.id); | |
| 34 assertEquals(0, offset_table.length % 3); | |
| 35 var lineNr = null; | |
| 36 var columnNr = null; | |
| 37 for (var p = 0; p < offset_table.length; p += 3) { | |
| 38 if (offset_table[p] != pos) continue; | |
| 39 lineNr = offset_table[p+1]; | |
| 40 columnNr = offset_table[p+2]; | |
| 41 } | |
| 42 assertNotNull(lineNr, "position should occur in offset table"); | |
| 43 assertNotNull(columnNr, "position should occur in offset table"); | |
| 44 var line = disassembly.split("\n")[lineNr]; | |
| 45 assertTrue(!!line, "line number must occur in disassembly"); | |
| 46 assertTrue(line.length > columnNr, "column number must be valid"); | |
| 47 var expected_string; | |
| 48 if (name.endsWith("/1")) { | |
| 49 // Function 0 calls the imported function. | |
| 50 expected_string = "kExprCallFunction,"; | |
| 51 } else if (name.endsWith("/2")) { | |
| 52 // Function 1 calls function 0. | |
| 53 expected_string = "kExprCallFunction,"; | |
| 54 } else { | |
| 55 assertTrue(false, "Unexpected wasm script: " + name); | |
| 56 } | |
| 57 assertTrue(line.substr(columnNr).startsWith(expected_string), | |
| 58 "offset " + columnNr + " should start with '" + expected_string | |
| 59 + "': " + line); | |
| 60 } | |
| 61 } | |
| 62 } else if (event == Debug.DebugEvent.AfterCompile) { | |
| 63 var script = event_data.script(); | |
| 64 if (script.scriptType() == Debug.ScriptType.Wasm) { | |
| 65 ++num_wasm_scripts; | |
| 66 } | |
| 67 } | |
| 68 } catch (e) { | |
| 69 print("exception: " + e); | |
| 70 exception = e; | |
| 71 } | |
| 72 }; | |
| 73 | |
| 74 var builder = new WasmModuleBuilder(); | |
| 75 | |
| 76 builder.addImport("func", kSig_v_v); | |
| 77 | |
| 78 builder.addFunction("call_import", kSig_v_v) | |
| 79 .addBody([kExprCallFunction, 0]) | |
| 80 .exportFunc(); | |
| 81 | |
| 82 // Add a bit of unneccessary code to increase the byte offset. | |
| 83 builder.addFunction("call_call_import", kSig_v_v) | |
| 84 .addLocals({i32_count: 2}) | |
| 85 .addBody([ | |
| 86 kExprI32Const, 27, kExprSetLocal, 0, | |
| 87 kExprI32Const, (-7 & 0x7f), kExprSetLocal, 1, | |
| 88 kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add, kExprI64UConvertI32, | |
| 89 kExprI64Const, 0, | |
| 90 kExprI64Ne, kExprIf, kAstStmt, | |
| 91 kExprCallFunction, 1, | |
| 92 kExprEnd | |
| 93 ]) | |
| 94 .exportFunc(); | |
| 95 | |
| 96 function call_debugger() { | |
| 97 debugger; | |
| 98 } | |
| 99 | |
| 100 function setup() { | |
| 101 module = builder.instantiate({func: call_debugger}); | |
| 102 exception = null; | |
| 103 break_count = 0; | |
| 104 num_wasm_scripts = 0; | |
| 105 } | |
| 106 | |
| 107 (function testRegisteredWasmScripts1() { | |
| 108 setup(); | |
| 109 Debug.setListener(listener); | |
| 110 // Call the "call_import" function -> 1 script. | |
| 111 module.exports.call_import(); | |
| 112 module.exports.call_import(); | |
| 113 module.exports.call_call_import(); | |
| 114 Debug.setListener(null); | |
| 115 | |
| 116 assertEquals(3, break_count); | |
| 117 if (exception) throw exception; | |
| 118 })(); | |
| 119 | |
| 120 (function testRegisteredWasmScripts2() { | |
| 121 setup(); | |
| 122 Debug.setListener(listener); | |
| 123 module.exports.call_call_import(); | |
| 124 Debug.setListener(null); | |
| 125 | |
| 126 assertEquals(1, break_count); | |
| 127 if (exception) throw exception; | |
| 128 })(); | |
| OLD | NEW |