Skip to content

Commit 9f22b8c

Browse files
committed
module: check -e flag in debug break setup
When both --debug-brk and --eval are set, and a filename is specified, its full path is not set correctly, causing an error for relative filenames with './' omitted. For example, 'node --debug-brk -e 0 hello.js' throws an error. Since the script referenced by the filename is never run anyway, this change skips resolving its full path if both --debug-brk and --eval are set.
1 parent f5d997c commit 9f22b8c

2 files changed

Lines changed: 44 additions & 29 deletions

File tree

lib/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Module.prototype._compile = function(content, filename) {
549549
displayErrors: true
550550
});
551551

552-
if (process._debugWaitConnect) {
552+
if (process._debugWaitConnect && process._eval == null) {
553553
if (!resolvedArgv) {
554554
// we enter the repl if we're not given a filename argument.
555555
if (process.argv[1]) {

test/parallel/test-debug-brk.js

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,48 @@
33
const common = require('../common');
44
const spawn = require('child_process').spawn;
55

6-
var procStderr = '';
7-
var agentStdout = '';
8-
var needToSpawnAgent = true;
9-
var needToExit = true;
10-
11-
const procArgs = [`--debug-brk=${common.PORT}`, '-e', '0'];
12-
const proc = spawn(process.execPath, procArgs);
13-
proc.stderr.setEncoding('utf8');
14-
15-
const exitAll = common.mustCall((processes) => {
16-
processes.forEach((myProcess) => { myProcess.kill(); });
17-
});
18-
19-
proc.stderr.on('data', (chunk) => {
20-
procStderr += chunk;
21-
if (/Debugger listening on/.test(procStderr) && needToSpawnAgent) {
22-
needToSpawnAgent = false;
23-
const agentArgs = ['debug', `localhost:${common.PORT}`];
24-
const agent = spawn(process.execPath, agentArgs);
25-
agent.stdout.setEncoding('utf8');
26-
27-
agent.stdout.on('data', (chunk) => {
28-
agentStdout += chunk;
29-
if (/connecting to .+ ok/.test(agentStdout) && needToExit) {
30-
needToExit = false;
31-
exitAll([proc, agent]);
6+
let run = () => {};
7+
function test(extraArgs) {
8+
const next = run;
9+
run = () => {
10+
var procStderr = '';
11+
var agentStdout = '';
12+
var needToSpawnAgent = true;
13+
var needToExit = true;
14+
15+
const procArgs = [`--debug-brk=${common.PORT}`].concat(extraArgs);
16+
const proc = spawn(process.execPath, procArgs);
17+
proc.stderr.setEncoding('utf8');
18+
19+
const exitAll = common.mustCall((processes) => {
20+
processes.forEach((myProcess) => { myProcess.kill(); });
21+
});
22+
23+
proc.stderr.on('data', (chunk) => {
24+
procStderr += chunk;
25+
if (/Debugger listening on/.test(procStderr) && needToSpawnAgent) {
26+
needToSpawnAgent = false;
27+
const agentArgs = ['debug', `localhost:${common.PORT}`];
28+
const agent = spawn(process.execPath, agentArgs);
29+
agent.stdout.setEncoding('utf8');
30+
31+
agent.stdout.on('data', (chunk) => {
32+
agentStdout += chunk;
33+
if (/connecting to .+ ok/.test(agentStdout) && needToExit) {
34+
needToExit = false;
35+
exitAll([proc, agent]);
36+
}
37+
});
3238
}
3339
});
34-
}
35-
});
40+
41+
proc.on('exit', () => {
42+
next();
43+
});
44+
};
45+
}
46+
47+
test(['-e', '0']);
48+
test(['-e', '0', 'foo']);
49+
50+
run();

0 commit comments

Comments
 (0)