[wasm][debug] Add test for conditional breakpoints

Conditional breakpoints are not implemented yet; the condition is just
ignored for wasm. This CL adds a test for conditional breakpoints. The
output is expected to change once the implementation is finished.

R=bmeurer@chromium.org

Bug: chromium:1173007
Change-Id: I15e0053ec8b57e28b8eadc208f35bbf70437682e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2666692
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72478}
This commit is contained in:
Clemens Backes 2021-02-02 11:38:53 +01:00 committed by Commit Bot
parent 44fa34084a
commit 1f85cb19df
2 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1,89 @@
Test conditional breakpoints in wasm.
Running test: test
Instantiating.
Waiting for wasm script.
Got wasm script: wasm://wasm/f00dbc56
Setting breakpoint at offset 34, condition "false"
{
id : <messageId>
result : {
actualLocation : {
columnNumber : 34
lineNumber : 0
scriptId : <scriptId>
}
breakpointId : <breakpointId>
}
}
Setting breakpoint at offset 41, condition "true"
{
id : <messageId>
result : {
actualLocation : {
columnNumber : 41
lineNumber : 0
scriptId : <scriptId>
}
breakpointId : <breakpointId>
}
}
Setting breakpoint at offset 46, condition "$var0==3"
{
id : <messageId>
result : {
actualLocation : {
columnNumber : 46
lineNumber : 0
scriptId : <scriptId>
}
breakpointId : <breakpointId>
}
}
NOTE: The conditions are being ignored currently.
Calling fib(5)
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 5
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 5
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
$var0: 5
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 4
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 4
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
$var0: 4
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 3
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 3
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
$var0: 3
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 2
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 2
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 1
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 1
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 2
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 2
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 3
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 3
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
$var0: 3
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 2
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 2
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
$var0: 1
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
$var0: 1
fib returned!

View File

@ -0,0 +1,75 @@
// Copyright 2021 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.
utils.load('test/inspector/wasm-inspector-test.js');
const {session, contextGroup, Protocol} =
InspectorTest.start('Test conditional breakpoints in wasm.');
session.setupScriptMap();
const builder = new WasmModuleBuilder();
const fib_body = [
kExprLocalGet, 0, // i (for br_if or i32.sub)
kExprLocalGet, 0, kExprI32Const, 2, kExprI32LeS, // i < 2 ?
kExprBrIf, 0, // --> return i
kExprI32Const, 1, kExprI32Sub, // i - 1
kExprCallFunction, 0, // fib(i - 1)
kExprLocalGet, 0, kExprI32Const, 2, kExprI32Sub, // i - 2
kExprCallFunction, 0, // fib(i - 2)
kExprI32Add // add (and return)
];
const fib = builder.addFunction('fib', kSig_i_i).addBody(fib_body).exportFunc();
const module_bytes = builder.toArray();
const find_offset = opcode => fib.body_offset + fib_body.indexOf(opcode);
const breakpoints = [
{loc: find_offset(kExprLocalGet), cond: 'false'},
{loc: find_offset(kExprBrIf), cond: 'true'},
{loc: find_offset(kExprCallFunction), cond: '$var0==3'}
];
Protocol.Debugger.onPaused(async msg => {
var frames = msg.params.callFrames;
await session.logSourceLocation(frames[0].location);
var frame = msg.params.callFrames[0];
for (var scope of frame.scopeChain) {
if (scope.type != 'local') continue;
var properties = await Protocol.Runtime.getProperties(
{'objectId': scope.object.objectId});
InspectorTest.log(properties.result.result.map(
value => `${value.name}: ${value.value.value}`));
}
Protocol.Debugger.resume();
});
InspectorTest.runAsyncTestSuite([
async function test() {
await Protocol.Debugger.enable();
InspectorTest.log('Instantiating.');
// Spawn asynchronously:
WasmInspectorTest.instantiate(module_bytes);
InspectorTest.log('Waiting for wasm script.');
const [, {params: wasm_script}] = await Protocol.Debugger.onceScriptParsed(2);
InspectorTest.log(`Got wasm script: ${wasm_script.url}`);
for (let breakpoint of breakpoints) {
InspectorTest.log(`Setting breakpoint at offset ${breakpoint.loc}, condition "${breakpoint.cond}"`);
InspectorTest.logMessage(await Protocol.Debugger.setBreakpoint({
'location': {
'scriptId': wasm_script.scriptId,
'lineNumber': 0,
'columnNumber': breakpoint.loc
},
condition: breakpoint.cond
}));
}
// TODO(1173007): Implement conditional breakpoints for wasm.
InspectorTest.log('NOTE: The conditions are being ignored currently.');
InspectorTest.log('Calling fib(5)');
await WasmInspectorTest.evalWithUrl('instance.exports.fib(5)', 'runWasm');
InspectorTest.log('fib returned!');
}
]);