v8/test/inspector/protocol-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

544 lines
19 KiB
JavaScript
Raw Normal View History

// Copyright 2016 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 = {};
InspectorTest._dumpInspectorProtocolMessages = false;
InspectorTest._commandsForLogging = new Set();
InspectorTest._sessions = new Set();
InspectorTest.log = utils.print.bind(utils);
InspectorTest.quitImmediately = utils.quit.bind(utils);
InspectorTest.logProtocolCommandCalls = function(command) {
InspectorTest._commandsForLogging.add(command);
}
InspectorTest.completeTest = function() {
var promises = [];
for (var session of InspectorTest._sessions)
promises.push(session.Protocol.Debugger.disable());
Promise.all(promises).then(() => utils.quit());
}
InspectorTest.waitForPendingTasks = function() {
var promises = [];
for (var session of InspectorTest._sessions)
promises.push(session.Protocol.Runtime.evaluate({ expression: "new Promise(r => setTimeout(r, 0))//# sourceURL=wait-for-pending-tasks.js", awaitPromise: true }));
return Promise.all(promises);
}
[debugger] tuned StepNext and StepOut at return position Proposed behaviour: - StepNext at return position go into next function call (no changes with current behavior, but implemented in v8::Debug instead of hack on inspector side); - StepOut at return position go into next non-current function call. We need this to have better stepping in cases with native functions, blackboxed functions and/or different embedder calls (e.g. event listeners). New behavior could be illustrated with two examples (for more see stepping-with-natives-and-frameworks test): - let's assume that we've blackboxed callAll function, this function just takes its arguments and call one after another: var foo = () => 1; callAll(foo, foo, () => 2); If we break inside of first call of function foo. Then on.. ..StepNext - we're able to reach second call of function foo, ..StepOut - we're able to reach () => 2 call. - let's consider case with native function: [1,2,3].map(x => x * 2) If we break inside of first callback call, then with StepNext we can iterate through all calls of callback, with StepOut we go to next statement after .map call. Implementation details: - when we request break we schedule step-in function call for any step action at return position and for step-in at any position, - when we request StepOut at return position - we mark current function as needed-to-be-ignored inside of PrepareStepIn(function) call, - when we request StepOut at not return position - we set break at return position and ask debugger to just repeat last step action on next stepping-related break. Design doc: https://docs.google.com/document/d/1ihXHOIhP_q-fJCA0e2EiXz_Zr3B08KMjaPifcaqZ60Q/edit BUG=v8:6118,chromium:583193 R=dgozman@chromium.org,yangguo@chromium.org Review-Url: https://codereview.chromium.org/2758483002 Cr-Commit-Position: refs/heads/master@{#44028}
2017-03-22 14:16:18 +00:00
InspectorTest.startDumpingProtocolMessages = function() {
InspectorTest._dumpInspectorProtocolMessages = true;
}
InspectorTest.logMessage = function(originalMessage) {
Reland [inspector] introduced stackTraceId and externalAsyncTask API Sometimes we need to capture stack trace on one debugger and use it later as a parent stack on another debugger (e.g. worker.postMessage). This CL includes following addition to our protocol and v8-inspector.h: - added Runtime.StackTraceId, this id represents stack trace captured on debugger with given id, - protocol client can fetch Runtime.StackTrace by Runtime.StacKTraceId using Debugger.getStackTrace method, - externalParent field is added to Debugger.paused event, it may contain external parent stack trace, - V8Inspector::storeCurrentStackTrace captures current stack trace and returns V8StackTraceId for embedder this id can be used as argument for V8Inspector::externalAsyncTaskStarted and V8Inspector::externalAsyncTaskFinished method. Any async stack trace captured between these calls will get passed external stack trace as external parent. These methods are designed to be called on different debuggers. If async task is scheduled and started on one debugger user should continue to use asyncTask* API, - Debugger.enable methods returns unique debuggerId. TBR=dgozman@chromium.org,jgruber@chromium.org Bug: chromium:778796 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I2c1a2b2e30ed69ccb61d10f08686f4edb09f50e4 Reviewed-on: https://chromium-review.googlesource.com/786274 Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#49591}
2017-11-22 19:46:33 +00:00
const nonStableFields = new Set([
'objectId', 'scriptId', 'exceptionId', 'timestamp', 'executionContextId',
'callFrameId', 'breakpointId', 'bindRemoteObjectFunctionId',
'formatterObjectId', 'debuggerId', 'bodyGetterId', 'uniqueId'
Reland [inspector] introduced stackTraceId and externalAsyncTask API Sometimes we need to capture stack trace on one debugger and use it later as a parent stack on another debugger (e.g. worker.postMessage). This CL includes following addition to our protocol and v8-inspector.h: - added Runtime.StackTraceId, this id represents stack trace captured on debugger with given id, - protocol client can fetch Runtime.StackTrace by Runtime.StacKTraceId using Debugger.getStackTrace method, - externalParent field is added to Debugger.paused event, it may contain external parent stack trace, - V8Inspector::storeCurrentStackTrace captures current stack trace and returns V8StackTraceId for embedder this id can be used as argument for V8Inspector::externalAsyncTaskStarted and V8Inspector::externalAsyncTaskFinished method. Any async stack trace captured between these calls will get passed external stack trace as external parent. These methods are designed to be called on different debuggers. If async task is scheduled and started on one debugger user should continue to use asyncTask* API, - Debugger.enable methods returns unique debuggerId. TBR=dgozman@chromium.org,jgruber@chromium.org Bug: chromium:778796 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I2c1a2b2e30ed69ccb61d10f08686f4edb09f50e4 Reviewed-on: https://chromium-review.googlesource.com/786274 Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#49591}
2017-11-22 19:46:33 +00:00
]);
const message = JSON.parse(JSON.stringify(originalMessage, replacer.bind(null, Symbol(), nonStableFields)));
if (message.id)
message.id = '<messageId>';
InspectorTest.logObject(message);
return originalMessage;
function replacer(stableIdSymbol, nonStableFields, name, val) {
if (nonStableFields.has(name))
return `<${name}>`;
if (name === 'internalProperties') {
const stableId = val.find(prop => prop.name === '[[StableObjectId]]');
if (stableId)
stableId.value[stableIdSymbol] = true;
}
if (name === 'parentId')
return { id: '<id>' };
if (val && val[stableIdSymbol])
return '<StablectObjectId>';
return val;
}
}
InspectorTest.logObject = function(object, title) {
var lines = [];
function dumpValue(value, prefix, prefixWithName) {
if (typeof value === "object" && value !== null) {
if (value instanceof Array)
dumpItems(value, prefix, prefixWithName);
else
dumpProperties(value, prefix, prefixWithName);
} else {
lines.push(prefixWithName + String(value).replace(/\n/g, " "));
}
}
function dumpProperties(object, prefix, firstLinePrefix) {
prefix = prefix || "";
firstLinePrefix = firstLinePrefix || prefix;
lines.push(firstLinePrefix + "{");
var propertyNames = Object.keys(object);
propertyNames.sort();
for (var i = 0; i < propertyNames.length; ++i) {
var name = propertyNames[i];
if (!object.hasOwnProperty(name))
continue;
var prefixWithName = " " + prefix + name + " : ";
dumpValue(object[name], " " + prefix, prefixWithName);
}
lines.push(prefix + "}");
}
function dumpItems(object, prefix, firstLinePrefix) {
prefix = prefix || "";
firstLinePrefix = firstLinePrefix || prefix;
lines.push(firstLinePrefix + "[");
for (var i = 0; i < object.length; ++i)
dumpValue(object[i], " " + prefix, " " + prefix + "[" + i + "] : ");
lines.push(prefix + "]");
}
dumpValue(object, "", title || "");
InspectorTest.log(lines.join("\n"));
}
InspectorTest.decodeBase64 = function(base64) {
const LOOKUP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const paddingLength = base64.match(/=*$/)[0].length;
const bytesLength = base64.length * 0.75 - paddingLength;
let bytes = new Uint8Array(bytesLength);
for (let i = 0, p = 0; i < base64.length; i += 4, p += 3) {
let bits = 0;
for (let j = 0; j < 4; j++) {
bits <<= 6;
const c = base64[i + j];
if (c !== '=') bits |= LOOKUP.indexOf(c);
}
for (let j = p + 2; j >= p; j--) {
if (j < bytesLength) bytes[j] = bits;
bits >>= 8;
}
}
return bytes;
}
InspectorTest.trimErrorMessage = function(message) {
if (!message.error || !message.error.data)
return message;
message.error.data = message.error.data.replace(/at position \d+/,
'at <some position>');
return message;
}
InspectorTest.ContextGroup = class {
constructor() {
this.id = utils.createContextGroup();
}
createContext(name) {
utils.createContext(this.id, name || '');
}
schedulePauseOnNextStatement(reason, details) {
utils.schedulePauseOnNextStatement(this.id, reason, details);
}
cancelPauseOnNextStatement() {
utils.cancelPauseOnNextStatement(this.id);
}
addScript(string, lineOffset, columnOffset, url) {
utils.compileAndRunWithOrigin(this.id, string, url || '', lineOffset || 0, columnOffset || 0, false);
}
addInlineScript(string, url) {
const match = (new Error().stack).split('\n')[2].match(/([0-9]+):([0-9]+)/);
this.addScript(
string, match[1] * 1, match[1] * 1 + '.addInlineScript('.length, url);
}
addModule(string, url, lineOffset, columnOffset) {
utils.compileAndRunWithOrigin(this.id, string, url, lineOffset || 0, columnOffset || 0, true);
}
loadScript(fileName) {
this.addScript(utils.read(fileName));
}
connect() {
return new InspectorTest.Session(this);
}
reset() {
utils.resetContextGroup(this.id);
}
setupInjectedScriptEnvironment(session) {
let scriptSource = '';
let getters = ["length","internalConstructorName","subtype","getProperty",
"objectHasOwnProperty","nullifyPrototype","primitiveTypes",
"closureTypes","prototype","all","RemoteObject","bind",
"PropertyDescriptor","object","get","set","value","configurable",
"enumerable","symbol","getPrototypeOf","nativeAccessorDescriptor",
"isBuiltin","hasGetter","hasSetter","getOwnPropertyDescriptor",
"description","isOwn","name",
"typedArrayProperties","keys","getOwnPropertyNames",
"getOwnPropertySymbols","isPrimitiveValue","com","toLowerCase",
"ELEMENT","trim","replace","DOCUMENT","size","byteLength","toString",
"stack","substr","message","indexOf","key","type","unserializableValue",
"objectId","className","preview","proxyTargetValue","customPreview",
"CustomPreview","resolve","then","console","error","header","hasBody",
"stringify","ObjectPreview","ObjectPreviewType","properties",
"ObjectPreviewSubtype","getInternalProperties","wasThrown","indexes",
"overflow","valuePreview","entries"];
scriptSource += `(function installSettersAndGetters() {
let defineProperty = Object.defineProperty;
let ObjectPrototype = Object.prototype;
let ArrayPrototype = Array.prototype;
defineProperty(ArrayPrototype, 0, {
set() { debugger; throw 42; }, get() { debugger; throw 42; },
__proto__: null
});`,
scriptSource += getters.map(getter => `
defineProperty(ObjectPrototype, '${getter}', {
set() { debugger; throw 42; }, get() { debugger; throw 42; },
__proto__: null
});
`).join('\n') + '})();';
this.addScript(scriptSource);
if (session) {
InspectorTest.log('WARNING: setupInjectedScriptEnvironment with debug flag for debugging only and should not be landed.');
session.setupScriptMap();
session.Protocol.Debugger.enable();
session.Protocol.Debugger.onPaused(message => {
let callFrames = message.params.callFrames;
session.logSourceLocations(callFrames.map(frame => frame.location));
})
}
}
};
InspectorTest.Session = class {
constructor(contextGroup) {
this.contextGroup = contextGroup;
this._dispatchTable = new Map();
this._eventHandlers = new Map();
this._requestId = 0;
this.Protocol = this._setupProtocol();
InspectorTest._sessions.add(this);
this.id = utils.connectSession(contextGroup.id, '', this._dispatchMessage.bind(this));
}
disconnect() {
InspectorTest._sessions.delete(this);
utils.disconnectSession(this.id);
}
reconnect() {
var state = utils.disconnectSession(this.id);
this.id = utils.connectSession(this.contextGroup.id, state, this._dispatchMessage.bind(this));
}
async addInspectedObject(serializable) {
return this.Protocol.Runtime.evaluate({expression: `inspector.addInspectedObject(${this.id}, ${JSON.stringify(serializable)})`});
}
sendRawCommand(requestId, command, handler) {
if (InspectorTest._dumpInspectorProtocolMessages)
utils.print("frontend: " + command);
this._dispatchTable.set(requestId, handler);
utils.sendMessageToBackend(this.id, command);
}
setupScriptMap() {
if (this._scriptMap)
return;
this._scriptMap = new Map();
}
getCallFrameUrl(frame) {
const {scriptId} = frame.location ? frame.location : frame;
return (this._scriptMap.get(scriptId) ?? frame).url;
}
logCallFrames(callFrames) {
for (var frame of callFrames) {
var functionName = frame.functionName || '(anonymous)';
var url = this.getCallFrameUrl(frame);
var lineNumber = frame.location ? frame.location.lineNumber : frame.lineNumber;
var columnNumber = frame.location ? frame.location.columnNumber : frame.columnNumber;
InspectorTest.log(`${functionName} (${url}:${lineNumber}:${columnNumber})`);
}
}
async getScriptWithSource(scriptId, forceSourceRequest) {
var script = this._scriptMap.get(scriptId);
if (forceSourceRequest || !(script.scriptSource || script.bytecode)) {
var message = await this.Protocol.Debugger.getScriptSource({ scriptId });
script.scriptSource = message.result.scriptSource;
if (message.result.bytecode) {
script.bytecode = InspectorTest.decodeBase64(message.result.bytecode);
}
}
return script;
}
async logSourceLocation(location, forceSourceRequest) {
var scriptId = location.scriptId;
if (!this._scriptMap || !this._scriptMap.has(scriptId)) {
InspectorTest.log("setupScriptMap should be called before Protocol.Debugger.enable.");
InspectorTest.completeTest();
}
var script = await this.getScriptWithSource(scriptId, forceSourceRequest);
if (script.bytecode) {
if (location.lineNumber != 0) {
InspectorTest.log('Unexpected wasm line number: ' + location.lineNumber);
}
let wasm_opcode = script.bytecode[location.columnNumber];
let opcode_str = wasm_opcode.toString(16);
if (opcode_str.length % 2) opcode_str = `0${opcode_str}`;
if (InspectorTest.getWasmOpcodeName) {
opcode_str += ` (${InspectorTest.getWasmOpcodeName(wasm_opcode)})`;
}
InspectorTest.log(`Script ${script.url} byte offset ${
location.columnNumber}: Wasm opcode 0x${opcode_str}`);
} else {
var lines = script.scriptSource.split('\n');
var line = lines[location.lineNumber];
line = line.slice(0, location.columnNumber) + '#' + (line.slice(location.columnNumber) || '');
lines[location.lineNumber] = line;
lines = lines.filter(line => line.indexOf('//# sourceURL=') === -1);
InspectorTest.log(lines.slice(Math.max(location.lineNumber - 1, 0), location.lineNumber + 2).join('\n'));
InspectorTest.log('');
}
}
logSourceLocations(locations) {
if (locations.length == 0) return Promise.resolve();
return this.logSourceLocation(locations[0]).then(() => this.logSourceLocations(locations.splice(1)));
}
async logBreakLocations(inputLocations) {
let locations = inputLocations.slice();
let scriptId = locations[0].scriptId;
let script = await this.getScriptWithSource(scriptId);
let lines = script.scriptSource.split('\n');
locations = locations.sort((loc1, loc2) => {
if (loc2.lineNumber !== loc1.lineNumber) return loc2.lineNumber - loc1.lineNumber;
return loc2.columnNumber - loc1.columnNumber;
});
for (let location of locations) {
let line = lines[location.lineNumber];
line = line.slice(0, location.columnNumber) + locationMark(location.type) + line.slice(location.columnNumber);
lines[location.lineNumber] = line;
}
lines = lines.filter(line => line.indexOf('//# sourceURL=') === -1);
InspectorTest.log(lines.join('\n') + '\n');
return inputLocations;
function locationMark(type) {
if (type === 'return') return '|R|';
if (type === 'call') return '|C|';
if (type === 'debuggerStatement') return '|D|';
return '|_|';
}
}
[type-profile] Incorporate into inspector protocol. JavaScript is a dynamically typed language. But most code is written with fixed types in mind. When debugging JavaScript, it is helpful to know the types of variables and parameters at runtime. It is often hard to infer types for complex code. Type profiling provides this information at runtime. Node.js uses the inspector protocol. This CL allows Node.js users to access and analyse type profile for via Node modules or the in-procress api. Type Profile helps developers to analyze their code for correctness and performance. Design doc: https://docs.google.com/a/google.com/document/d/1O1uepXZXBI6IwiawTrYC3ohhiNgzkyTdjn3R8ysbYgk/edit?usp=sharing Add `takeTypeProfile` to the inspector protocol. It returns a list of TypeProfileForScripts, which in turn contains the type profile for each function. We can use TypeProfile data to annotate JavaScript code. Sample script with data from TypeProfile: function f(/*Object, number, undefined*/a, /*Array, number, null*/b, /*boolean, Object, symbol*/c) { return 'bye'; /*string*/}; f({}, [], true); f(3, 2.3, {a: 42}); f(undefined, null, Symbol('hello'));/*string*/ Bug: v8:5933 Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I626bfb886b752f90b9c86cc6953601558b18b60d Reviewed-on: https://chromium-review.googlesource.com/508588 Commit-Queue: Franziska Hinkelmann <franzih@chromium.org> Reviewed-by: Pavel Feldman <pfeldman@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/master@{#47920}
2017-09-08 08:28:29 +00:00
async logTypeProfile(typeProfile, source) {
let entries = typeProfile.entries;
// Sort in reverse order so we can replace entries without invalidating
// the other offsets.
entries = entries.sort((a, b) => b.offset - a.offset);
for (let entry of entries) {
source = source.slice(0, entry.offset) + typeAnnotation(entry.types) +
source.slice(entry.offset);
}
InspectorTest.log(source);
return typeProfile;
function typeAnnotation(types) {
return `/*${types.map(t => t.name).join(', ')}*/`;
}
}
logAsyncStackTrace(asyncStackTrace) {
while (asyncStackTrace) {
InspectorTest.log(`-- ${asyncStackTrace.description || '<empty>'} --`);
this.logCallFrames(asyncStackTrace.callFrames);
if (asyncStackTrace.parentId) InspectorTest.log(' <external stack>');
asyncStackTrace = asyncStackTrace.parent;
}
}
_sendCommandPromise(method, params) {
if (typeof params !== 'object')
utils.print(`WARNING: non-object params passed to invocation of method ${method}`);
if (InspectorTest._commandsForLogging.has(method))
utils.print(method + ' called');
var requestId = ++this._requestId;
var messageObject = { "id": requestId, "method": method, "params": params };
return new Promise(fulfill => this.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill));
}
_setupProtocol() {
return new Proxy({}, { get: (target, agentName, receiver) => new Proxy({}, {
get: (target, methodName, receiver) => {
const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/;
var match = eventPattern.exec(methodName);
if (!match)
return args => this._sendCommandPromise(`${agentName}.${methodName}`, args || {});
var eventName = match[2];
eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1);
if (match[1])
return numOfEvents => this._waitForEventPromise(
`${agentName}.${eventName}`, numOfEvents || 1);
return listener => this._eventHandlers.set(`${agentName}.${eventName}`, listener);
}
})});
}
_dispatchMessage(messageString) {
var messageObject = JSON.parse(messageString);
if (InspectorTest._dumpInspectorProtocolMessages)
utils.print("backend: " + JSON.stringify(messageObject));
const kMethodNotFound = -32601;
if (messageObject.error && messageObject.error.code === kMethodNotFound) {
InspectorTest.log(`Error: Called non-existent method. ${
messageObject.error.message} code: ${messageObject.error.code}`);
InspectorTest.completeTest();
}
try {
var messageId = messageObject["id"];
if (typeof messageId === "number") {
var handler = this._dispatchTable.get(messageId);
if (handler) {
handler(messageObject);
this._dispatchTable.delete(messageId);
}
} else {
var eventName = messageObject["method"];
var eventHandler = this._eventHandlers.get(eventName);
if (this._scriptMap && eventName === "Debugger.scriptParsed")
this._scriptMap.set(messageObject.params.scriptId, JSON.parse(JSON.stringify(messageObject.params)));
if (eventName === "Debugger.scriptParsed" && messageObject.params.url === "wait-for-pending-tasks.js")
return;
if (eventHandler)
eventHandler(messageObject);
}
} catch (e) {
InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stack + "\n message = " + JSON.stringify(messageObject, null, 2));
InspectorTest.completeTest();
}
};
_waitForEventPromise(eventName, numOfEvents) {
let events = [];
return new Promise(fulfill => {
this._eventHandlers.set(eventName, result => {
--numOfEvents;
events.push(result);
if (numOfEvents === 0) {
delete this._eventHandlers.delete(eventName);
fulfill(events.length > 1 ? events : events[0]);
}
});
});
}
};
InspectorTest.runTestSuite = function(testSuite) {
function nextTest() {
if (!testSuite.length) {
InspectorTest.completeTest();
return;
}
var fun = testSuite.shift();
InspectorTest.log("\nRunning test: " + fun.name);
fun(nextTest);
}
nextTest();
}
InspectorTest.runAsyncTestSuite = async function(testSuite) {
const selected = testSuite.filter(test => test.name.startsWith('f_'));
if (selected.length)
testSuite = selected;
for (var test of testSuite) {
InspectorTest.log("\nRunning test: " + test.name);
try {
await test();
} catch (e) {
utils.print(e.stack);
}
}
InspectorTest.completeTest();
}
InspectorTest.start = function(description) {
try {
InspectorTest.log(description);
var contextGroup = new InspectorTest.ContextGroup();
var session = contextGroup.connect();
return { session: session, contextGroup: contextGroup, Protocol: session.Protocol };
} catch (e) {
utils.print(e.stack);
}
}
/**
* Two helper functions for the tests in `debugger/restart-frame/*`.
*/
InspectorTest.evaluateAndWaitForPause = async (expression) => {
const pausedPromise = Protocol.Debugger.oncePaused();
const evaluatePromise = Protocol.Runtime.evaluate({ expression });
const { params: { callFrames } } = await pausedPromise;
InspectorTest.log('Paused at (after evaluation):');
await session.logSourceLocation(callFrames[0].location);
// Ignore the last frame, it's always an anonymous empty frame for the
// Runtime#evaluate call.
InspectorTest.log('Pause stack:');
for (const frame of callFrames.slice(0, -1)) {
InspectorTest.log(` ${frame.functionName}:${frame.location.lineNumber} (canBeRestarted = ${frame.canBeRestarted ?? false})`);
}
InspectorTest.log('');
return { callFrames, evaluatePromise };
};
[inspector] Add 'canBeRestarted' flag to CallFrames when debugger pauses Doc: https://bit.ly/revive-restart-frame Context: https://crrev.com/c/3582395 (whole feature) This CL adds a new optional flag `canBeRestarted` to every call frame in Debugger.paused events. As the name suggests, the flag indicates whether we can restart a particular frame through Debugger.restartFrame once implemented. We are not able to safely restart all frames: * We don't support WASM frames * We don't support frames where resumable functions (async fns, generators) and embedder C++ frames are between the top-most frame and the to-be-restarted frame. Note that from a CDP perspective the flag doesn't actually guarantee a successful restart. CDP clients can issue CDP commands between the Debugger.paused event and before a user decides to restart a frame, which can potentially mess with the stack. The `canBeRestarted` flag tests are folded into the Debugger.restartFrame tests. As the feature is not yet fully implemented we short-circuit most of the tests for now and only run them up until the first Debugger.restartFrame call fails (except "fails-for-resumables.js"). This means the tests exercise the `canBeRestarted` flag, but not the restarting functionality itself. R=bmeurer@chromium.org, kimanh@chromium.org Bug: chromium:1303521 Change-Id: I01ab46dc3557ab8383960969fbe03e00604cc5e2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3596160 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Kim-Anh Tran <kimanh@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org> Cr-Commit-Position: refs/heads/main@{#80046}
2022-04-20 11:55:39 +00:00
// TODO(crbug.com/1303521): Remove `quitOnFailure` once no longer needed.
InspectorTest.restartFrameAndWaitForPause = async (callFrames, index, quitOnFailure = true) => {
const pausedPromise = Protocol.Debugger.oncePaused();
const frame = callFrames[index];
InspectorTest.log(`Restarting function "${frame.functionName}" ...`);
const response = await Protocol.Debugger.restartFrame({ callFrameId: frame.callFrameId, mode: 'StepInto' });
if (response.error) {
InspectorTest.log(`Failed to restart function "${frame.functionName}":`);
InspectorTest.logMessage(response.error);
[inspector] Add 'canBeRestarted' flag to CallFrames when debugger pauses Doc: https://bit.ly/revive-restart-frame Context: https://crrev.com/c/3582395 (whole feature) This CL adds a new optional flag `canBeRestarted` to every call frame in Debugger.paused events. As the name suggests, the flag indicates whether we can restart a particular frame through Debugger.restartFrame once implemented. We are not able to safely restart all frames: * We don't support WASM frames * We don't support frames where resumable functions (async fns, generators) and embedder C++ frames are between the top-most frame and the to-be-restarted frame. Note that from a CDP perspective the flag doesn't actually guarantee a successful restart. CDP clients can issue CDP commands between the Debugger.paused event and before a user decides to restart a frame, which can potentially mess with the stack. The `canBeRestarted` flag tests are folded into the Debugger.restartFrame tests. As the feature is not yet fully implemented we short-circuit most of the tests for now and only run them up until the first Debugger.restartFrame call fails (except "fails-for-resumables.js"). This means the tests exercise the `canBeRestarted` flag, but not the restarting functionality itself. R=bmeurer@chromium.org, kimanh@chromium.org Bug: chromium:1303521 Change-Id: I01ab46dc3557ab8383960969fbe03e00604cc5e2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3596160 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Kim-Anh Tran <kimanh@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org> Cr-Commit-Position: refs/heads/main@{#80046}
2022-04-20 11:55:39 +00:00
if (quitOnFailure) {
InspectorTest.completeTest();
}
return;
}
const { params: { callFrames: pausedCallFrames } } = await pausedPromise;
InspectorTest.log('Paused at (after restart):');
await session.logSourceLocation(pausedCallFrames[0].location);
return callFrames;
};