Skip to content

Commit 1f85cb1

Browse files
backesCommit Bot
authored andcommitted
[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}
1 parent 44fa340 commit 1f85cb1

2 files changed

Lines changed: 164 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Test conditional breakpoints in wasm.
2+
3+
Running test: test
4+
Instantiating.
5+
Waiting for wasm script.
6+
Got wasm script: wasm://wasm/f00dbc56
7+
Setting breakpoint at offset 34, condition "false"
8+
{
9+
id : <messageId>
10+
result : {
11+
actualLocation : {
12+
columnNumber : 34
13+
lineNumber : 0
14+
scriptId : <scriptId>
15+
}
16+
breakpointId : <breakpointId>
17+
}
18+
}
19+
Setting breakpoint at offset 41, condition "true"
20+
{
21+
id : <messageId>
22+
result : {
23+
actualLocation : {
24+
columnNumber : 41
25+
lineNumber : 0
26+
scriptId : <scriptId>
27+
}
28+
breakpointId : <breakpointId>
29+
}
30+
}
31+
Setting breakpoint at offset 46, condition "$var0==3"
32+
{
33+
id : <messageId>
34+
result : {
35+
actualLocation : {
36+
columnNumber : 46
37+
lineNumber : 0
38+
scriptId : <scriptId>
39+
}
40+
breakpointId : <breakpointId>
41+
}
42+
}
43+
NOTE: The conditions are being ignored currently.
44+
Calling fib(5)
45+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
46+
$var0: 5
47+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
48+
$var0: 5
49+
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
50+
$var0: 5
51+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
52+
$var0: 4
53+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
54+
$var0: 4
55+
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
56+
$var0: 4
57+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
58+
$var0: 3
59+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
60+
$var0: 3
61+
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
62+
$var0: 3
63+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
64+
$var0: 2
65+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
66+
$var0: 2
67+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
68+
$var0: 1
69+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
70+
$var0: 1
71+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
72+
$var0: 2
73+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
74+
$var0: 2
75+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
76+
$var0: 3
77+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
78+
$var0: 3
79+
Script wasm://wasm/f00dbc56 byte offset 46: Wasm opcode 0x10 (kExprCallFunction)
80+
$var0: 3
81+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
82+
$var0: 2
83+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
84+
$var0: 2
85+
Script wasm://wasm/f00dbc56 byte offset 34: Wasm opcode 0x20 (kExprLocalGet)
86+
$var0: 1
87+
Script wasm://wasm/f00dbc56 byte offset 41: Wasm opcode 0x0d (kExprBrIf)
88+
$var0: 1
89+
fib returned!
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2021 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+
utils.load('test/inspector/wasm-inspector-test.js');
6+
7+
const {session, contextGroup, Protocol} =
8+
InspectorTest.start('Test conditional breakpoints in wasm.');
9+
session.setupScriptMap();
10+
11+
const builder = new WasmModuleBuilder();
12+
13+
const fib_body = [
14+
kExprLocalGet, 0, // i (for br_if or i32.sub)
15+
kExprLocalGet, 0, kExprI32Const, 2, kExprI32LeS, // i < 2 ?
16+
kExprBrIf, 0, // --> return i
17+
kExprI32Const, 1, kExprI32Sub, // i - 1
18+
kExprCallFunction, 0, // fib(i - 1)
19+
kExprLocalGet, 0, kExprI32Const, 2, kExprI32Sub, // i - 2
20+
kExprCallFunction, 0, // fib(i - 2)
21+
kExprI32Add // add (and return)
22+
];
23+
const fib = builder.addFunction('fib', kSig_i_i).addBody(fib_body).exportFunc();
24+
25+
const module_bytes = builder.toArray();
26+
27+
const find_offset = opcode => fib.body_offset + fib_body.indexOf(opcode);
28+
29+
const breakpoints = [
30+
{loc: find_offset(kExprLocalGet), cond: 'false'},
31+
{loc: find_offset(kExprBrIf), cond: 'true'},
32+
{loc: find_offset(kExprCallFunction), cond: '$var0==3'}
33+
];
34+
35+
Protocol.Debugger.onPaused(async msg => {
36+
var frames = msg.params.callFrames;
37+
await session.logSourceLocation(frames[0].location);
38+
var frame = msg.params.callFrames[0];
39+
for (var scope of frame.scopeChain) {
40+
if (scope.type != 'local') continue;
41+
var properties = await Protocol.Runtime.getProperties(
42+
{'objectId': scope.object.objectId});
43+
InspectorTest.log(properties.result.result.map(
44+
value => `${value.name}: ${value.value.value}`));
45+
}
46+
Protocol.Debugger.resume();
47+
});
48+
49+
InspectorTest.runAsyncTestSuite([
50+
async function test() {
51+
await Protocol.Debugger.enable();
52+
InspectorTest.log('Instantiating.');
53+
// Spawn asynchronously:
54+
WasmInspectorTest.instantiate(module_bytes);
55+
InspectorTest.log('Waiting for wasm script.');
56+
const [, {params: wasm_script}] = await Protocol.Debugger.onceScriptParsed(2);
57+
InspectorTest.log(`Got wasm script: ${wasm_script.url}`);
58+
for (let breakpoint of breakpoints) {
59+
InspectorTest.log(`Setting breakpoint at offset ${breakpoint.loc}, condition "${breakpoint.cond}"`);
60+
InspectorTest.logMessage(await Protocol.Debugger.setBreakpoint({
61+
'location': {
62+
'scriptId': wasm_script.scriptId,
63+
'lineNumber': 0,
64+
'columnNumber': breakpoint.loc
65+
},
66+
condition: breakpoint.cond
67+
}));
68+
}
69+
// TODO(1173007): Implement conditional breakpoints for wasm.
70+
InspectorTest.log('NOTE: The conditions are being ignored currently.');
71+
InspectorTest.log('Calling fib(5)');
72+
await WasmInspectorTest.evalWithUrl('instance.exports.fib(5)', 'runWasm');
73+
InspectorTest.log('fib returned!');
74+
}
75+
]);

0 commit comments

Comments
 (0)