v8/test/inspector/debugger/set-instrumentation-breakpoint.js
Kim-Anh Tran 0c3fdff2d2 [debug] Capture more cases for instrumentation breakpoints
The previous implementation would not explicitly send
`Debugger.paused` events for instrumentation breakpoints
if they were to overlap with breaks due to:
* regular breakpoints
* OOM
* exceptions
* asserts

This CL is a step towards making sure that a separate
`Debugger.paused` event is always sent for an instrumentation
breakpoint. In some cases where we have overlapping reasons
but only know of one, the 'instrumentation' reason,
we still just send out one paused event with the reason
being `instrumentation`.

Drive-by: send instrumentation notification to all sessions,
remember which breakpoints are instrumentation breakpoints

Bug: chromium:1229541, chromium:1133307
Change-Id: Ie15438f78b8b81a89c64fa291ce7ecc36ebb2182
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3211892
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77333}
2021-10-12 08:53:39 +00:00

168 lines
7.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.
const { session, contextGroup, Protocol } = InspectorTest.start(
'Debugger.setInstrumentationBreakpoint');
InspectorTest.runAsyncTestSuite([
async function testSetTwice() {
await Protocol.Debugger.enable();
const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptExecution'
});
InspectorTest.log('set breakpoint..');
InspectorTest.logMessage(firstResult);
InspectorTest.log('set breakpoint again..');
InspectorTest.logMessage(await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptExecution'
}));
InspectorTest.log('remove breakpoint..');
InspectorTest.logMessage(await Protocol.Debugger.removeBreakpoint({
breakpointId: firstResult.breakpointId
}));
await Protocol.Debugger.disable();
},
async function testScriptParsed() {
await Protocol.Debugger.enable();
InspectorTest.log('set breakpoint and evaluate script..');
const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptExecution'
});
Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
{
const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason}`);
InspectorTest.logMessage(data);
}
await Protocol.Debugger.resume();
InspectorTest.log('set breakpoint and evaluate script with sourceMappingURL..');
Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js\n//# sourceMappingURL=map.js'});
{
const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason}`);
InspectorTest.logMessage(data);
}
InspectorTest.log('remove breakpoint..');
InspectorTest.logMessage(await Protocol.Debugger.removeBreakpoint({
breakpointId: firstResult.breakpointId
}));
InspectorTest.log('evaluate script again..');
await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
await Protocol.Debugger.disable();
},
async function testScriptWithSourceMapParsed() {
await Protocol.Debugger.enable();
InspectorTest.log('set breakpoint for scriptWithSourceMapParsed..');
const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptWithSourceMapExecution'
});
InspectorTest.log('evaluate script without sourceMappingURL..')
await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
InspectorTest.log('evaluate script with sourceMappingURL..')
Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js\n//# sourceMappingURL=map.js'});
{
const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason}`);
InspectorTest.logMessage(data);
}
InspectorTest.log('remove breakpoint..')
InspectorTest.logMessage(await Protocol.Debugger.removeBreakpoint({
breakpointId: firstResult.breakpointId
}));
InspectorTest.log('evaluate script without sourceMappingURL..')
await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
InspectorTest.log('evaluate script with sourceMappingURL..')
await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js\n//# sourceMappingURL=map.js'});
await Protocol.Debugger.disable();
},
async function testBlackboxing() {
await Protocol.Debugger.enable();
await Protocol.Debugger.setBlackboxPatterns({patterns: ['foo\.js']});
InspectorTest.log('set breakpoint and evaluate blackboxed script..');
const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptExecution'
});
await Protocol.Runtime.evaluate({expression: '//# sourceURL=foo.js'});
InspectorTest.log('evaluate not blackboxed script..');
Protocol.Runtime.evaluate({expression: '//# sourceURL=bar.js'});
{
const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason}`);
InspectorTest.logMessage(data);
}
await Protocol.Debugger.resume();
InspectorTest.log('evaluate blackboxed script that contains not blackboxed one..');
Protocol.Runtime.evaluate({expression: `eval('//# sourceURL=bar.js')//# sourceURL=foo.js`});
{
const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason}`);
InspectorTest.logMessage(data);
}
await Protocol.Debugger.resume();
await Protocol.Debugger.disable();
},
async function testCompileFirstRunLater() {
await Protocol.Runtime.enable();
await Protocol.Debugger.enable();
InspectorTest.log('set breakpoint for scriptWithSourceMapParsed..');
const { result : firstResult } = await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptWithSourceMapExecution'
});
InspectorTest.log('compile script with sourceMappingURL..');
const { result: { scriptId } } = await Protocol.Runtime.compileScript({
expression: '//# sourceMappingURL=boo.js', sourceURL: 'foo.js', persistScript: true });
InspectorTest.log('evaluate script without sourceMappingURL..');
await Protocol.Runtime.evaluate({ expression: '' });
InspectorTest.log('run previously compiled script with sourceMappingURL..');
Protocol.Runtime.runScript({ scriptId });
{
const { params: { reason, data } } = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason}`);
InspectorTest.logMessage(data);
}
await Protocol.Debugger.disable();
await Protocol.Runtime.disable();
},
async function testCoincideWithRegularBreakpoint() {
await Protocol.Runtime.enable();
await Protocol.Debugger.enable();
InspectorTest.log('regular breakpoint and instrumentation breakpoint are reported');
const instrumentationResult = await Protocol.Debugger.setInstrumentationBreakpoint({
instrumentation: 'beforeScriptExecution'
});
InspectorTest.log(`Set breakpoint: ${instrumentationResult.result.breakpointId}`);
const { result: { scriptId } } = await Protocol.Runtime.compileScript({
expression: 'console.log(3);', sourceURL: 'test.js', persistScript: true });
const breakpoinResult = await Protocol.Debugger.setBreakpointByUrl({
lineNumber: 0,
url: 'test.js',
columnNumber: 0
});
InspectorTest.log(`Set breakpoint: ${breakpoinResult.result.breakpointId}`);
const runPromise = Protocol.Runtime.runScript({scriptId});
{
const {params: {reason, hitBreakpoints}} = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason} and breakpoints: ${hitBreakpoints}`);
await Protocol.Debugger.resume();
}
{
const {params: {reason, hitBreakpoints}} = await Protocol.Debugger.oncePaused();
InspectorTest.log(`paused with reason: ${reason} and breakpoints: ${hitBreakpoints}`);
await Protocol.Debugger.resume();
}
await runPromise;
await Protocol.Debugger.disable();
await Protocol.Runtime.disable();
}]
);