Commit 579c1e29 authored by dgozman's avatar dgozman Committed by Commit Bot

[inspector] Test how multiple sessions interact with pausing

Found multiple issues (added TODOs for them):
- isPaused() check is global, so one can resume from another session/context group
  without receiving 'paused' notification;
- setBreakpointsActive flag is global affecting all sessions and context groups;
- max async call stack depth is global, and should be per context group.

BUG=chromium:590878

Review-Url: https://codereview.chromium.org/2921373002
Cr-Commit-Position: refs/heads/master@{#45742}
parent 07b958fa
......@@ -286,6 +286,7 @@ void V8DebuggerAgentImpl::restore() {
Response V8DebuggerAgentImpl::setBreakpointsActive(bool active) {
if (!enabled()) return Response::Error(kDebuggerNotEnabled);
// TODO(dgozman): this state should be per-session, not global per debugger.
m_debugger->setBreakpointsActivated(active);
if (!active && !m_breakReason.empty()) {
clearBreakDetails();
......@@ -1033,7 +1034,11 @@ V8DebuggerAgentImpl::currentAsyncStackTrace() {
m_debugger->maxAsyncCallChainDepth() - 1);
}
bool V8DebuggerAgentImpl::isPaused() const { return m_debugger->isPaused(); }
bool V8DebuggerAgentImpl::isPaused() const {
// TODO(dgozman): this check allows once context group to resume the other,
// since they share debugger.
return m_debugger->isPaused();
}
void V8DebuggerAgentImpl::didParseSource(
std::unique_ptr<V8DebuggerScript> script, bool success) {
......
......@@ -960,6 +960,7 @@ void V8Debugger::setAsyncCallStackDepth(V8DebuggerAgentImpl* agent, int depth) {
}
if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) return;
// TODO(dgozman): ideally, this should be per context group.
m_maxAsyncCallStackDepth = maxAsyncCallStackDepth;
if (!maxAsyncCallStackDepth) allAsyncTasksCanceled();
}
......
Tests how multiple sessions interact while pausing, stepping, setting breakpoints and blackboxing.
Setting breakpoints in 1
Setting breakpoints in 2
Evaluating common breakpoint in 1
Paused in 2:
reason: other
hit breakpoints: test.js:11:0
location: foo@11
data: null
Paused in 1:
reason: other
hit breakpoints: test.js:11:0
location: foo@11
data: null
Resuming in 1
Resumed in 2
Resumed in 1
Evaluating debugger in 1
Paused in 2:
reason: other
hit breakpoints:
location: bar@25
data: null
Paused in 1:
reason: other
hit breakpoints:
location: bar@25
data: null
Resuming in 2
Resumed in 2
Resumed in 1
Evaluating exclusive breakpoint in 1
Paused in 2:
reason: other
hit breakpoints:
location: baz@14
data: null
Paused in 1:
reason: other
hit breakpoints: test.js:14:0
location: baz@14
data: null
Resuming in 1
Resumed in 2
Resumed in 1
Evaluating common breakpoint in 2
Paused in 2:
reason: other
hit breakpoints: test.js:11:0
location: foo@11
data: null
Paused in 1:
reason: other
hit breakpoints: test.js:11:0
location: foo@11
data: null
Resuming in 2
Resumed in 2
Resumed in 1
Evaluating debugger in 2
Paused in 2:
reason: other
hit breakpoints:
location: bar@25
data: null
Paused in 1:
reason: other
hit breakpoints:
location: bar@25
data: null
Resuming in 2
Resumed in 2
Resumed in 1
Evaluating exclusive breakpoint in 2
Paused in 2:
reason: other
hit breakpoints:
location: baz@14
data: null
Paused in 1:
reason: other
hit breakpoints: test.js:14:0
location: baz@14
data: null
Resuming in 1
Resumed in 2
Resumed in 1
Evaluating stepping in 1
Paused in 2:
reason: other
hit breakpoints:
location: stepping@17
data: null
Paused in 1:
reason: other
hit breakpoints:
location: stepping@17
data: null
Stepping into in 2
Resumed in 2
Resumed in 1
Paused in 2:
reason: other
hit breakpoints:
location: stepping@18
data: null
Paused in 1:
reason: other
hit breakpoints:
location: stepping@18
data: null
Stepping over in 1
Resumed in 2
Resumed in 1
Paused in 2:
reason: other
hit breakpoints:
location: stepping@19
data: null
Paused in 1:
reason: other
hit breakpoints:
location: stepping@19
data: null
Stepping out in 2
Resumed in 2
Resumed in 1
Paused in 2:
reason: other
hit breakpoints:
location: <anonymous>@0
data: null
Paused in 1:
reason: other
hit breakpoints:
location: <anonymous>@0
data: null
Resuming in 1
Resumed in 2
Resumed in 1
Pausing in next statement
Paused in 2:
reason: some-reason
hit breakpoints:
location: <anonymous>@0
data: {"a":42}
Paused in 1:
reason: some-reason
hit breakpoints:
location: <anonymous>@0
data: {"a":42}
Resuming in 1
Resumed in 2
Resumed in 1
Pausing in next statement
Paused in 2:
reason: some-reason
hit breakpoints:
location: <anonymous>@0
data: {"a":42}
Paused in 1:
reason: some-reason
hit breakpoints:
location: <anonymous>@0
data: {"a":42}
Resuming in 2
Resumed in 2
Resumed in 1
Blackboxing bar() in 2
Evaluating bar() in 2
Paused in 1:
reason: other
hit breakpoints:
location: bar@25
data: null
Resuming in 1
Resumed in 1
Blackboxing bar() in 1
Evaluating bar() in 2
Skipping pauses in 1
Evaluating common breakpoint in 1
Paused in 2:
reason: other
hit breakpoints: test.js:11:0
location: foo@11
data: null
Resuming in 2
Resumed in 2
Skipping pauses in 2
Evaluating common breakpoint in 1
// Copyright 2017 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.
InspectorTest.log('Tests how multiple sessions interact while pausing, stepping, setting breakpoints and blackboxing.');
var contextGroup = new InspectorTest.ContextGroup();
contextGroup.addScript(`
function foo() {
return 1;
}
function baz() {
return 2;
}
function stepping() {
debugger;
var a = 1;
var b = 1;
}
//# sourceURL=test.js`, 9, 25);
contextGroup.addScript(`
function bar() {
debugger;
}
//# sourceURL=test2.js`, 23, 25);
(async function test() {
var session1 = contextGroup.connect();
await session1.Protocol.Debugger.enable();
var session2 = contextGroup.connect();
await session2.Protocol.Debugger.enable();
InspectorTest.log('Setting breakpoints in 1');
await session1.Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumber: 11});
await session1.Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumber: 14});
InspectorTest.log('Setting breakpoints in 2');
await session2.Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumber: 11});
InspectorTest.log('Evaluating common breakpoint in 1');
session1.Protocol.Runtime.evaluate({expression: 'foo();'});
await waitForBothPaused();
InspectorTest.log('Resuming in 1');
session1.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Evaluating debugger in 1');
session1.Protocol.Runtime.evaluate({expression: 'bar();'});
await waitForBothPaused();
InspectorTest.log('Resuming in 2');
session2.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Evaluating exclusive breakpoint in 1');
session1.Protocol.Runtime.evaluate({expression: 'baz();'});
await waitForBothPaused();
InspectorTest.log('Resuming in 1');
session1.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Evaluating common breakpoint in 2');
session2.Protocol.Runtime.evaluate({expression: 'foo();'});
await waitForBothPaused();
InspectorTest.log('Resuming in 2');
session2.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Evaluating debugger in 2');
session2.Protocol.Runtime.evaluate({expression: 'bar();'});
await waitForBothPaused();
InspectorTest.log('Resuming in 2');
session2.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Evaluating exclusive breakpoint in 2');
session2.Protocol.Runtime.evaluate({expression: 'baz();'});
await waitForBothPaused();
InspectorTest.log('Resuming in 1');
session1.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Evaluating stepping in 1');
session1.Protocol.Runtime.evaluate({expression: 'stepping();'});
await waitForBothPaused();
InspectorTest.log('Stepping into in 2');
session2.Protocol.Debugger.stepInto();
await waitForBothResumed();
await waitForBothPaused();
InspectorTest.log('Stepping over in 1');
session1.Protocol.Debugger.stepOver();
await waitForBothResumed();
await waitForBothPaused();
InspectorTest.log('Stepping out in 2');
session2.Protocol.Debugger.stepOut();
await waitForBothResumed();
await waitForBothPaused();
InspectorTest.log('Resuming in 1');
session1.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Pausing in next statement');
contextGroup.schedulePauseOnNextStatement('some-reason', JSON.stringify({a: 42}));
session2.Protocol.Runtime.evaluate({expression: 'var a = 1;'});
await waitForBothPaused();
InspectorTest.log('Resuming in 1');
session1.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Pausing in next statement');
contextGroup.schedulePauseOnNextStatement('some-reason', JSON.stringify({a: 42}));
session2.Protocol.Runtime.evaluate({expression: 'var a = 1;'});
await waitForBothPaused();
InspectorTest.log('Resuming in 2');
session2.Protocol.Debugger.resume();
await waitForBothResumed();
InspectorTest.log('Blackboxing bar() in 2');
await session2.Protocol.Debugger.setBlackboxPatterns({patterns: ['test2.js']});
InspectorTest.log('Evaluating bar() in 2');
session2.Protocol.Runtime.evaluate({expression: 'bar();'});
await waitForPaused(session1, 1);
InspectorTest.log('Resuming in 1');
session1.Protocol.Debugger.resume();
await waitForResumed(session1, 1);
InspectorTest.log('Blackboxing bar() in 1');
await session1.Protocol.Debugger.setBlackboxPatterns({patterns: ['test2.js']});
InspectorTest.log('Evaluating bar() in 2');
await session2.Protocol.Runtime.evaluate({expression: 'bar();'});
InspectorTest.log('Skipping pauses in 1');
await session1.Protocol.Debugger.setSkipAllPauses({skip: true});
InspectorTest.log('Evaluating common breakpoint in 1');
session1.Protocol.Runtime.evaluate({expression: 'foo();'});
await waitForPaused(session2, 2);
InspectorTest.log('Resuming in 2');
session2.Protocol.Debugger.resume();
await waitForResumed(session2, 2);
InspectorTest.log('Skipping pauses in 2');
await session2.Protocol.Debugger.setSkipAllPauses({skip: true});
InspectorTest.log('Evaluating common breakpoint in 1');
await session1.Protocol.Runtime.evaluate({expression: 'foo();'});
InspectorTest.completeTest();
function waitForBothPaused() {
return Promise.all([waitForPaused(session1, 1), waitForPaused(session2, 2)]);
}
function waitForBothResumed() {
return Promise.all([waitForResumed(session1, 1), waitForResumed(session2, 2)]);
}
})();
function waitForPaused(session, num) {
return session.Protocol.Debugger.oncePaused().then(message => {
InspectorTest.log(`Paused in ${num}:`);
InspectorTest.log(` reason: ${message.params.reason}`);
InspectorTest.log(` hit breakpoints: ${(message.params.hitBreakpoints || []).join(';')}`);
var callFrame = message.params.callFrames[0];
InspectorTest.log(` location: ${callFrame.functionName || '<anonymous>'}@${callFrame.location.lineNumber}`);
InspectorTest.log(` data: ${JSON.stringify(message.params.data || null)}`);
});
}
function waitForResumed(session, num) {
return session.Protocol.Debugger.onceResumed().then(message => {
InspectorTest.log(`Resumed in ${num}`);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment