v8/test/debugger/debug/wasm/frame-inspection.js
jgruber 9eec1c8617 [debug-wrapper] Migrate wasm/frame-inspection test
Wasm frames are special in that they have a non-integer script id
in inspector. The way we treat script ids currently is a bit of a mess -
our runtime functions expected integer IDs while inspector has string
IDs (which contain integers, except for Wasm frames). This will need to
be cleaned up once more Wasm tests are added.

The meaning of line/column numbers has also changed; the old JS debug
API encoded the function index and byte offset into line/column numbers,
while inspector-based API actually translates into lines/columns in the
disassembly.

BUG=v8:5530

Review-Url: https://codereview.chromium.org/2515133003
Cr-Commit-Position: refs/heads/master@{#41182}
2016-11-22 13:59:05 +00:00

73 lines
1.9 KiB
JavaScript

// 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");
Debug = debug.Debug
var exception = null;
var break_count = 0;
const expected_frames = [
// func-name; wasm?; pos; line; col
['call_debugger', false], // --
['wasm_2', true, 56, 2, 0], // --
['wasm_1', true, 52, 3, 0], // --
['testFrameInspection', false], // --
['', false]
];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
++break_count;
try {
var break_id = exec_state.break_id;
var frame_count = exec_state.frameCount();
assertEquals(expected_frames.length, frame_count, 'frame count');
for (var i = 0; i < frame_count; ++i) {
var frame = exec_state.frame(i);
assertEquals(expected_frames[i][0], frame.func().name(), 'name at ' + i);
if (expected_frames[i][1]) { // wasm frame?
assertEquals(expected_frames[i][3], frame.sourceLine(), 'line at ' + i);
assertEquals(expected_frames[i][4], frame.sourceColumn(),
'column at ' + i);
}
}
} catch (e) {
exception = e;
}
};
var builder = new WasmModuleBuilder();
// wasm_1 calls wasm_2 on offset 2.
// wasm_2 calls call_debugger on offset 1.
builder.addImport('func', kSig_v_v);
builder.addFunction('wasm_1', kSig_v_v)
.addBody([kExprNop, kExprCallFunction, 2])
.exportAs('main');
builder.addFunction('wasm_2', kSig_v_v).addBody([kExprCallFunction, 0]);
function call_debugger() {
debugger;
}
var module = builder.instantiate({func: call_debugger});
(function testFrameInspection() {
Debug.setListener(listener);
module.exports.main();
Debug.setListener(null);
assertEquals(1, break_count);
if (exception) throw exception;
})();