Skip to content

Commit ebff29f

Browse files
kjinMatt Loring
authored and
Matt Loring
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. PR-URL: #8876 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 74f0e51 commit ebff29f

File tree

2 files changed

+64
-29
lines changed

2 files changed

+64
-29
lines changed

lib/module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ Module.prototype._compile = function(content, filename) {
548548
displayErrors: true
549549
});
550550

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

test/parallel/test-debug-brk.js

+63-28
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,68 @@
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, stdoutPattern) {
8+
const next = run;
9+
run = () => {
10+
var procStdout = '';
11+
var procStderr = '';
12+
var agentStdout = '';
13+
var debuggerListening = false;
14+
var outputMatched = false;
15+
var needToSpawnAgent = true;
16+
var needToExit = true;
17+
18+
const procArgs = [`--debug-brk=${common.PORT}`].concat(extraArgs);
19+
const proc = spawn(process.execPath, procArgs);
20+
proc.stderr.setEncoding('utf8');
21+
22+
const tryStartAgent = () => {
23+
if (debuggerListening && outputMatched && needToSpawnAgent) {
24+
needToSpawnAgent = false;
25+
const agentArgs = ['debug', `localhost:${common.PORT}`];
26+
const agent = spawn(process.execPath, agentArgs);
27+
agent.stdout.setEncoding('utf8');
28+
29+
agent.stdout.on('data', (chunk) => {
30+
agentStdout += chunk;
31+
if (/connecting to .+ ok/.test(agentStdout) && needToExit) {
32+
needToExit = false;
33+
exitAll([proc, agent]);
34+
}
35+
});
3236
}
37+
};
38+
39+
const exitAll = common.mustCall((processes) => {
40+
processes.forEach((myProcess) => { myProcess.kill(); });
3341
});
34-
}
35-
});
42+
43+
if (stdoutPattern != null) {
44+
proc.stdout.on('data', (chunk) => {
45+
procStdout += chunk;
46+
outputMatched = outputMatched || stdoutPattern.test(procStdout);
47+
tryStartAgent();
48+
});
49+
} else {
50+
outputMatched = true;
51+
}
52+
53+
proc.stderr.on('data', (chunk) => {
54+
procStderr += chunk;
55+
debuggerListening = debuggerListening ||
56+
/Debugger listening on/.test(procStderr);
57+
tryStartAgent();
58+
});
59+
60+
proc.on('exit', () => {
61+
next();
62+
});
63+
};
64+
}
65+
66+
test(['-e', '0']);
67+
test(['-e', '0', 'foo']);
68+
test(['-p', 'process.argv[1]', 'foo'], /^\s*foo\s*$/);
69+
70+
run();

0 commit comments

Comments
 (0)