Created
October 22, 2020 00:24
-
-
Save jasonLaster/d19daf8cdb5c88cd94904f0c4bea3d1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/control/pause.js b/src/control/pause.js | |
| index 81fa72ce..21e97750 100644 | |
| --- a/src/control/pause.js | |
| +++ b/src/control/pause.js | |
| @@ -28,6 +28,7 @@ const { | |
| const { getGeneratedScriptLocation, getGeneratedScriptRanges } = require("./sourcemaps"); | |
| const Channel = require("./channel"); | |
| const Errors = require("../protocol/errors"); | |
| +const { spawnAsync } = require("../shared/instanceUtils"); | |
| // Map SessionId to PauseState | |
| const gSessionState = new Map(); | |
| @@ -173,94 +174,96 @@ async function findStepTarget(sessionId, point, forward, resumeLimit) { | |
| } | |
| async function findResumeTarget(sessionId, point, forward, resumeLimit) { | |
| - assert(!resumeLimit || ["next", "step", "finish"].includes(resumeLimit)); | |
| + traceFunction("findResumeTarget", async () => { | |
| + assert(!resumeLimit || ["next", "step", "finish"].includes(resumeLimit)); | |
| - let checkpoint = point.checkpoint; | |
| - if (!forward && !point.position) { | |
| - checkpoint--; | |
| - } | |
| - checkpoint = getSavedCheckpoint(checkpoint); | |
| + let checkpoint = point.checkpoint; | |
| + if (!forward && !point.position) { | |
| + checkpoint--; | |
| + } | |
| + checkpoint = getSavedCheckpoint(checkpoint); | |
| - const { breakpoints, blackboxedScripts } = getSessionState(sessionId); | |
| + const { breakpoints, blackboxedScripts } = getSessionState(sessionId); | |
| - // If we are stepping, find the next step target. | |
| - let stepTarget; | |
| - if (resumeLimit) { | |
| - stepTarget = await findStepTarget(sessionId, point, forward, resumeLimit); | |
| - } | |
| - | |
| - while (true) { | |
| - if (checkpoint == InvalidCheckpointId) { | |
| - assert(!forward); | |
| - return { | |
| - target: checkpointExecutionPoint(FirstCheckpointId), | |
| - reason: "endpoint", | |
| - }; | |
| + // If we are stepping, find the next step target. | |
| + let stepTarget; | |
| + if (resumeLimit) { | |
| + stepTarget = await findStepTarget(sessionId, point, forward, resumeLimit); | |
| } | |
| - if (checkpoint == lastSavedCheckpoint()) { | |
| - assert(forward); | |
| - return { | |
| - target: checkpointExecutionPoint(lastSavedCheckpoint()), | |
| - reason: "endpoint", | |
| - }; | |
| - } | |
| + while (true) { | |
| + if (checkpoint == InvalidCheckpointId) { | |
| + assert(!forward); | |
| + return { | |
| + target: checkpointExecutionPoint(FirstCheckpointId), | |
| + reason: "endpoint", | |
| + }; | |
| + } | |
| - const hits = []; | |
| - | |
| - // The step target is a potential hit, if it is in the range of this saved | |
| - // checkpoint. It might be in another part of the recording when stepping | |
| - // across an await/yield. | |
| - if ( | |
| - stepTarget && | |
| - stepTarget.checkpoint >= checkpoint && | |
| - stepTarget.checkpoint < nextSavedCheckpoint(checkpoint) | |
| - ) { | |
| - hits.push({ point: stepTarget, reason: "step" }); | |
| - } | |
| + if (checkpoint == lastSavedCheckpoint()) { | |
| + assert(forward); | |
| + return { | |
| + target: checkpointExecutionPoint(lastSavedCheckpoint()), | |
| + reason: "endpoint", | |
| + }; | |
| + } | |
| - for (const { position } of breakpoints.values()) { | |
| - const breakpointHits = await findHits(checkpoint, position); | |
| - hits.push(...breakpointHits.map(point => ({ point, reason: "breakpoint" }))); | |
| - } | |
| + const hits = []; | |
| - const { debuggerStatements } = savedCheckpointInfo(checkpoint); | |
| + // The step target is a potential hit, if it is in the range of this saved | |
| + // checkpoint. It might be in another part of the recording when stepping | |
| + // across an await/yield. | |
| + if ( | |
| + stepTarget && | |
| + stepTarget.checkpoint >= checkpoint && | |
| + stepTarget.checkpoint < nextSavedCheckpoint(checkpoint) | |
| + ) { | |
| + hits.push({ point: stepTarget, reason: "step" }); | |
| + } | |
| - // Debugger statements are time warp targets. | |
| - const debuggerStatementPoints = await Promise.all( | |
| - debuggerStatements.map(getTimeWarpTargetPoint) | |
| - ); | |
| + for (const { position } of breakpoints.values()) { | |
| + const breakpointHits = await findHits(checkpoint, position); | |
| + hits.push(...breakpointHits.map(point => ({ point, reason: "breakpoint" }))); | |
| + } | |
| - hits.push( | |
| - ...debuggerStatementPoints.map(point => ({ | |
| - point, | |
| - reason: "debuggerStatement", | |
| - })) | |
| - ); | |
| + const { debuggerStatements } = savedCheckpointInfo(checkpoint); | |
| - let hitPoints = hits.map(i => i.point); | |
| + // Debugger statements are time warp targets. | |
| + const debuggerStatementPoints = await Promise.all( | |
| + debuggerStatements.map(getTimeWarpTargetPoint) | |
| + ); | |
| - while (true) { | |
| - const hit = findClosestPoint(hitPoints, point, !forward, false); | |
| - if (!hit) { | |
| - break; | |
| - } | |
| + hits.push( | |
| + ...debuggerStatementPoints.map(point => ({ | |
| + point, | |
| + reason: "debuggerStatement", | |
| + })) | |
| + ); | |
| - // Ignore hits which are blackboxed. Such hits can't come from stepping, | |
| - // which already checked that the source wasn't blackboxed. | |
| - if (blackboxedScripts.has(hit.position.script)) { | |
| - hitPoints = hitPoints.filter(p => !pointEquals(p, hit)); | |
| - continue; | |
| + let hitPoints = hits.map(i => i.point); | |
| + | |
| + while (true) { | |
| + const hit = findClosestPoint(hitPoints, point, !forward, false); | |
| + if (!hit) { | |
| + break; | |
| + } | |
| + | |
| + // Ignore hits which are blackboxed. Such hits can't come from stepping, | |
| + // which already checked that the source wasn't blackboxed. | |
| + if (blackboxedScripts.has(hit.position.script)) { | |
| + hitPoints = hitPoints.filter(p => !pointEquals(p, hit)); | |
| + continue; | |
| + } | |
| + | |
| + const { reason } = hits.find(i => pointEquals(hit, i.point)); | |
| + return { target: hit, reason }; | |
| } | |
| - const { reason } = hits.find(i => pointEquals(hit, i.point)); | |
| - return { target: hit, reason }; | |
| + checkpoint = forward | |
| + ? nextSavedCheckpoint(checkpoint) | |
| + : previousSavedCheckpoint(checkpoint); | |
| } | |
| - | |
| - checkpoint = forward | |
| - ? nextSavedCheckpoint(checkpoint) | |
| - : previousSavedCheckpoint(checkpoint); | |
| - } | |
| + }) | |
| } | |
| /////////////////////// | |
| @@ -296,15 +299,27 @@ Channel.addMessageHandler("Debugger.removeBreakpoint", function ({ breakpointId | |
| return {}; | |
| }); | |
| +async function wrapInSpan(spanName, cbk) { | |
| + const parentSpan = tracer.getCurrentSpan() | |
| + const span = tracer.startSpan(spanName) | |
| + let results | |
| + tracer.withSpan(parentSpan, async () => { | |
| + results = await cbk() | |
| + }) | |
| + span.end() | |
| + return results; | |
| +} | |
| + | |
| function addResumeOperationHandler(command, forward, resumeLimit) { | |
| Channel.addMessageHandler(command, async function ({ point }) { | |
| point = await stringToPoint(point); | |
| - const { target, reason } = await findResumeTarget( | |
| + | |
| + const { target, reason } = await wrapInSpan("findResumeTarget", () => findResumeTarget( | |
| this.sessionId, | |
| point, | |
| forward, | |
| resumeLimit | |
| - ); | |
| + )); | |
| const desc = await getPointDescription(target); | |
| return { target: { ...desc, reason } }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment