Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lib/internal/debugger/inspect_probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ class ProbeInspectorSession {
this.inFlight = null;
// Most recently completed probe, used for `error.probe` when a non-evaluate CDP call rejects.
this.lastProbeIndex = null;
this.deferredStartupPause = null;
this.handledPauseAfterStart = false;
const { promise, resolve } = PromiseWithResolvers();
this.completionPromise = promise;
this.resolveCompletion = resolve;
Expand Down Expand Up @@ -624,10 +626,17 @@ class ProbeInspectorSession {

async handlePaused(params) {
if (this.finished) { return; }
// Ignore pauses that arrive before breakpoint setup is complete. Once
// Defer pauses that arrive before breakpoint setup is complete. Once
// startup is marked complete, `Runtime.runIfWaitingForDebugger` may surface
// the initial --inspect-brk pause, which the normal resume path handles.
if (!this.started) { return; }
// the initial --inspect-brk pause, which the normal resume path handles. If
// it was already surfaced while binding breakpoints, replay it after startup
// so the target is not left paused forever.
if (!this.started) {
this.deferredStartupPause = params;
return;
}

this.handledPauseAfterStart = true;

const hitBreakpoints = params.hitBreakpoints;
if (hitBreakpoints === undefined || hitBreakpoints.length === 0) {
Expand Down Expand Up @@ -676,6 +685,16 @@ class ProbeInspectorSession {
await this.resume();
}

async handleDeferredStartupPause() {
if (this.deferredStartupPause === null || this.handledPauseAfterStart) {
return;
}

const params = this.deferredStartupPause;
this.deferredStartupPause = null;
await this.handlePaused(params);
}

async evaluateProbe(callFrameId, probeIndex, location) {
if (this.finished) { return; }
const probe = this.probes[probeIndex];
Expand Down Expand Up @@ -998,6 +1017,7 @@ class ProbeInspectorSession {
this.started = true;
this.startTimeout();
await this.callCdp('Runtime.runIfWaitingForDebugger');
await this.handleDeferredStartupPause();
} catch (err) {
if (err !== kInspectorFailedSentinel) { throw err; }
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-debugger-probe-startup-pause.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Flags: --expose-internals
// This tests that probe mode ignores pauses until startup has finished binding
// This tests that probe mode defers pauses until startup has finished binding
// breakpoints.
'use strict';

Expand All @@ -25,7 +25,7 @@ async function testStartupPauseHandling() {
assert.deepStrictEqual(cdpCalls, []);

session.started = true;
await session.handlePaused({});
await session.handleDeferredStartupPause();
assert.deepStrictEqual(cdpCalls, ['Debugger.resume']);
}

Expand Down
Loading