v8/test/debugger/debug/wasm/debug-step-into-wasm.js
Z Nguyen-Huu 271bb94a62 [wasm] Support stepping back to Javascript from Wasm
This scenario is where user is at the end of Wasm execution and do
some stepping. Hence, user should be back at Javascript frame. We
can detect that stepping as it exits Wasm Interpreter and prepare
debugging as a step-out-ish in Javascript.

Bug: chromium:823923, chromium:1019606, chromium:1025151
Change-Id: I29022af0d5e5dcf78d87e83193f6e16fec954e87
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1912985
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65122}
2019-11-22 17:16:17 +00:00

93 lines
2.4 KiB
JavaScript

// Copyright 2019 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-module-builder.js");
var builder = new WasmModuleBuilder();
builder.addFunction('sub', kSig_i_ii)
// input is 2 args of type int and output is int
.addBody([
kExprLocalGet, 0, // local.get i0
kExprLocalGet, 1, // local.get i1
kExprI32Sub]) // i32.sub i0 i1
.exportFunc();
const instance = builder.instantiate();
const wasm_f = instance.exports.sub;
Debug = debug.Debug;
var exception = null;
var js_break_line = 0;
var break_count = 0;
var wasm_break_count = 0;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
print(event_data.sourceLineText());
print(event_data.functionName());
if (event_data.sourceLineText() == 'Debug.setListener(null);') {
return;
}
if (event_data.functionName() == 'f') {
break_count++;
assertTrue(
event_data.sourceLineText().indexOf(`Line ${js_break_line}.`) > 0);
js_break_line++;
} else {
assertTrue(event_data.functionName() == 'sub');
wasm_break_count++;
}
exec_state.prepareStep(Debug.StepAction.StepIn);
} catch (e) {
exception = e;
print(e);
}
};
function f() {
var result = wasm_f(3, 2); // Line 0.
result++; // Line 1.
return result; // Line 2.
}
assertEquals(2, f());
Debug.setListener(listener);
// Set a breakpoint on line 0.
Debug.setBreakPoint(f, 1);
// Set a breakpoint on line 2.
Debug.setBreakPoint(f, 3);
f();
Debug.setListener(null);
var break_count2 = 0;
// In the second execution, only break at javascript frame.
function listener2(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
print(event_data.sourceLineText());
if (event_data.sourceLineText() == 'Debug.setListener(null);') {
return;
}
print(event_data.functionName());
assertTrue(event_data.sourceLineText().indexOf(`Line `) > 0);
assertEquals(event_data.functionName(), 'f');
break_count2++;
exec_state.prepareStep(Debug.StepAction.StepOut);
} catch (e) {
exception = e;
print(e);
}
};
Debug.setListener(listener2);
f();
Debug.setListener(null);
assertEquals(break_count, 3);
assertEquals(js_break_line, 3);
assertEquals(wasm_break_count, 4);
assertEquals(break_count2, 2);
assertNull(exception);