Skip to content

Commit 512ca16

Browse files
committed
fixup! debugger: add edit-free runtime expression probes to node inspect
1 parent 4278d22 commit 512ca16

2 files changed

Lines changed: 17 additions & 50 deletions

File tree

lib/internal/debugger/inspect.js

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayFrom,
45
ArrayIsArray,
56
ArrayPrototypeForEach,
67
ArrayPrototypeJoin,
@@ -143,37 +144,18 @@ function parseUnsignedInteger(value, name, allowZero = false) {
143144
return parsed;
144145
}
145146

146-
// Parse from right to left to allow Windows paths with drive letters.
147147
// Accepts file:line or file:line:column formats.
148+
// Non-greedy (.+?) allows Windows drive-letter paths like C:\foo.js:10.
148149
function parseProbeLocation(text) {
149-
const lastColon = StringPrototypeLastIndexOf(text, ':');
150-
if (lastColon === -1) {
151-
throw new ERR_DEBUGGER_STARTUP_ERROR(`Invalid probe location: ${text}`);
152-
}
153-
154-
const right = StringPrototypeSlice(text, lastColon + 1);
155-
if (RegExpPrototypeExec(kDigitsRegex, right) === null) {
156-
throw new ERR_DEBUGGER_STARTUP_ERROR(`Invalid probe location: ${text}`);
157-
}
158-
159-
let file = StringPrototypeSlice(text, 0, lastColon);
160-
let line = parseUnsignedInteger(right, 'probe location');
161-
let column;
162-
163-
const secondColon = StringPrototypeLastIndexOf(file, ':');
164-
if (secondColon !== -1) {
165-
const maybeLine = StringPrototypeSlice(file, secondColon + 1);
166-
if (RegExpPrototypeExec(kDigitsRegex, maybeLine) !== null) {
167-
column = line;
168-
line = parseUnsignedInteger(maybeLine, 'probe location');
169-
file = StringPrototypeSlice(file, 0, secondColon);
170-
}
171-
}
172-
173-
if (file.length === 0) {
150+
const match = RegExpPrototypeExec(/^(.+?):(\d+)(?::(\d+))?$/, text);
151+
if (match === null) {
174152
throw new ERR_DEBUGGER_STARTUP_ERROR(`Invalid probe location: ${text}`);
175153
}
176154

155+
const file = match[1];
156+
const line = parseUnsignedInteger(match[2], 'probe location');
157+
const column = match[3] !== undefined ?
158+
parseUnsignedInteger(match[3], 'probe location') : undefined;
177159
const target = column === undefined ? [file, line] : [file, line, column];
178160

179161
return {
@@ -184,21 +166,12 @@ function parseProbeLocation(text) {
184166
};
185167
}
186168

187-
function formatProbeTuple(tuple) {
188-
return ArrayPrototypeJoin(ArrayPrototypeMap(tuple, (part) => `${part}`), ':');
189-
}
190-
191169
function formatPendingProbeLocations(probes, pending) {
192170
const seen = new SafeSet();
193-
const names = [];
194171
for (const probeIndex of pending) {
195-
const location = formatProbeTuple(probes[probeIndex].target);
196-
if (!seen.has(location)) {
197-
seen.add(location);
198-
ArrayPrototypePush(names, location);
199-
}
172+
seen.add(ArrayPrototypeJoin(probes[probeIndex].target, ':'));
200173
}
201-
return ArrayPrototypeJoin(names, ', ');
174+
return ArrayPrototypeJoin(ArrayFrom(seen), ', ');
202175
}
203176

204177
function formatTargetExitMessage(probes, pending, exitCode, signal) {
@@ -324,7 +297,7 @@ function buildProbeTextReport(report) {
324297
for (const result of report.results) {
325298
if (result.event === 'hit') {
326299
const probe = report.probes[result.probe];
327-
const location = formatProbeTuple(probe.target);
300+
const location = ArrayPrototypeJoin(probe.target, ':');
328301
ArrayPrototypePush(lines, `Hit ${result.hit} at ${location}`);
329302
if (result.error !== undefined) {
330303
ArrayPrototypePush(lines,
@@ -891,14 +864,6 @@ class ProbeInspectorSession {
891864
}
892865
}
893866

894-
async function runScript(script, scriptArgs, inspectHost, inspectPort,
895-
childPrint) {
896-
return launchChildProcess([script, ...scriptArgs],
897-
inspectHost,
898-
inspectPort,
899-
childPrint);
900-
}
901-
902867
function createAgentProxy(domain, client) {
903868
const agent = new EventEmitter();
904869
agent.then = (then, _catch) => {
@@ -933,9 +898,8 @@ class NodeInspector {
933898

934899
if (options.script) {
935900
this._runScript = FunctionPrototypeBind(
936-
runScript, null,
937-
options.script,
938-
options.scriptArgs,
901+
launchChildProcess, null,
902+
[options.script, ...options.scriptArgs],
939903
options.host,
940904
options.port,
941905
FunctionPrototypeBind(this.childPrint, this));

test/parallel/test-debugger-probe-activation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// This tests that probe mode only activates when --probe is present.
1+
// This tests that probe mode only activates when --probe is present,
2+
// so that other options can be used as user script arguments without
3+
// accidentally activating probe mode.
24
'use strict';
35

46
const common = require('../common');
@@ -24,6 +26,7 @@ const cli = startCLI([
2426
await cli.waitForInitialBreak();
2527
await cli.waitForPrompt();
2628
await cli.command('exec JSON.stringify(process.argv.slice(2))');
29+
// Check that it's parsable as usual.
2730
assert.match(
2831
cli.output,
2932
/\["--json","--preview","--timeout=1","--expr","value"\]/,

0 commit comments

Comments
 (0)