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 var exception = null; |
| 13 var break_count = 0; |
| 14 |
| 15 const expected_num_frames = 5; |
| 16 const expected_wasm_frames = [false, true, true, false, false]; |
| 17 const expected_wasm_positions = [0, 1, 2, 0, 0]; |
| 18 const expected_function_names = ["call_debugger", "wasm_2", "wasm_1", "testFrame
Inspection", ""]; |
| 19 |
| 20 function listener(event, exec_state, event_data, data) { |
| 21 if (event != Debug.DebugEvent.Break) return; |
| 22 ++break_count; |
| 23 try { |
| 24 var break_id = exec_state.break_id; |
| 25 var frame_count = exec_state.frameCount(); |
| 26 assertEquals(expected_num_frames, frame_count); |
| 27 |
| 28 for (var i = 0; i < frame_count; ++i) { |
| 29 var frame = exec_state.frame(i); |
| 30 // wasm frames have unresolved function, others resolved ones. |
| 31 assertEquals(expected_wasm_frames[i], !frame.func().resolved()); |
| 32 assertEquals(expected_function_names[i], frame.func().name()); |
| 33 if (expected_wasm_frames[i]) { |
| 34 var script = frame.details().script(); |
| 35 assertNotNull(script); |
| 36 assertEquals(expected_wasm_positions[i], frame.details().sourcePosition(
)); |
| 37 var loc = script.locationFromPosition(frame.details().sourcePosition()); |
| 38 assertEquals(expected_wasm_positions[i], loc.column); |
| 39 assertEquals(expected_wasm_positions[i], loc.position); |
| 40 } |
| 41 } |
| 42 } catch (e) { |
| 43 exception = e; |
| 44 } |
| 45 }; |
| 46 |
| 47 var builder = new WasmModuleBuilder(); |
| 48 |
| 49 // wasm_1 calls wasm_2 on offset 2. |
| 50 // wasm_2 calls call_debugger on offset 1. |
| 51 |
| 52 builder.addImport("func", kSig_v_v); |
| 53 |
| 54 builder.addFunction("wasm_1", kSig_v_v) |
| 55 .addBody([kExprNop, kExprCallFunction, kArity0, 1]) |
| 56 .exportAs("main"); |
| 57 |
| 58 builder.addFunction("wasm_2", kSig_v_v) |
| 59 .addBody([kExprCallImport, kArity0, 0]); |
| 60 |
| 61 function call_debugger() { |
| 62 debugger; |
| 63 } |
| 64 |
| 65 var module = builder.instantiate({func: call_debugger}); |
| 66 |
| 67 (function testFrameInspection() { |
| 68 Debug.setListener(listener); |
| 69 module.exports.main(); |
| 70 Debug.setListener(null); |
| 71 |
| 72 assertEquals(1, break_count); |
| 73 if (exception) throw exception; |
| 74 })(); |
OLD | NEW |