v8/test/inspector/debugger/step-into-external-async-task-same-context.js
Dmitry Gozman fe3d51e1b2 [inspector] Simplify async stepping
Currently, debugger pauses on async call schedule and then waits for Debugger.pauseOnAsyncCall
with parentStackTraceId to actually schedule the pause.

This CL combines these two steps:
- For local async tasks, it just stores m_taskWithScheduledBreak at the time of schedule,
  to be able to pause once this task is run.
- For external async tasks, it plumbs "should_pause" boolean in V8StackTraceId from
  the point of schedule to the point of execution, and schedules a pause once
  externalAsyncTaskStarted is called with "should_pause" set to true.

This approach greatly simplifies the implementation, and reduced frontend to a single
"breakOnAsyncCall: true" parameter in Debugger.stepInto.

Drive-by: introduce hasScheduledBreakOnNextFunctionCall() to make
SetBreakOnNextFunctionCall management more robust.

Note: artificial pauses at async call schedule time are gone from test expectations -
we now only pause when user actually wants to pause, which makes protocol much simpler.

See also design doc linked in the bug.

BUG=chromium:1000475

Change-Id: I2d16f79c599fe196b2aaeca8223c63437a2954a9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1783724
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63737}
2019-09-13 02:33:22 +00:00

75 lines
2.4 KiB
JavaScript

// 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.
let {session, contextGroup, Protocol} =
InspectorTest.start('Test for step-into remote async task.');
contextGroup.addScript(`
function store(description) {
let buffer = inspector.storeCurrentStackTrace(description);
return '[' + new Int32Array(buffer).join(',') + ']';
}
//# sourceURL=utils.js`);
contextGroup.addScript(`
function call(id, f) {
inspector.externalAsyncTaskStarted(Int32Array.from(JSON.parse(id)).buffer);
f();
inspector.externalAsyncTaskFinished(Int32Array.from(JSON.parse(id)).buffer);
}
//# sourceURL=framework.js`);
session.setupScriptMap();
(async function test() {
InspectorTest.log('Setup debugger agents..');
let debuggerId = (await Protocol.Debugger.enable()).result.debuggerId;
Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128});
Protocol.Debugger.setBlackboxPatterns({patterns: ['framework\.js']});
InspectorTest.log('Pause before stack trace is captured..');
Protocol.Debugger.setBreakpointByUrl(
{lineNumber: 2, columnNumber: 25, url: 'utils.js'});
let evaluatePromise = Protocol.Runtime.evaluate({
expression: `(function foo() {
return store('remote-task');
})()
//# sourceURL=source.js`
});
await Protocol.Debugger.oncePaused();
InspectorTest.log('Run stepInto with breakOnAsyncCall flag');
Protocol.Debugger.stepInto({breakOnAsyncCall: true});
InspectorTest.log('Trigger external async task on another context group');
let stackTraceId = (await evaluatePromise).result.result.value;
Protocol.Runtime.evaluate({
expression: `call('${stackTraceId}',
function boo() {})
//# sourceURL=target.js`
});
InspectorTest.log('Dump stack trace');
let {params: {callFrames, asyncStackTraceId}} =
await Protocol.Debugger.oncePaused();
while (true) {
session.logCallFrames(callFrames);
if (asyncStackTraceId) {
let {result: {stackTrace}} = await Protocol.Debugger.getStackTrace(
{stackTraceId: asyncStackTraceId});
InspectorTest.log(`-- ${stackTrace.description} --`);
callFrames = stackTrace.callFrames;
asyncStackTraceId = stackTrace.parentId;
} else {
break;
}
}
Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 0});
await Protocol.Debugger.disable();
InspectorTest.completeTest();
})()