Browse Source

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: https://github.com/nodejs/node/pull/8876
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6
Kelvin Jin 8 years ago
committed by Matt Loring
parent
commit
ebff29f2fe
  1. 2
      lib/module.js
  2. 91
      test/parallel/test-debug-brk.js

2
lib/module.js

@ -548,7 +548,7 @@ Module.prototype._compile = function(content, filename) {
displayErrors: true displayErrors: true
}); });
if (process._debugWaitConnect) { if (process._debugWaitConnect && process._eval == null) {
if (!resolvedArgv) { if (!resolvedArgv) {
// we enter the repl if we're not given a filename argument. // we enter the repl if we're not given a filename argument.
if (process.argv[1]) { if (process.argv[1]) {

91
test/parallel/test-debug-brk.js

@ -3,33 +3,68 @@
const common = require('../common'); const common = require('../common');
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
var procStderr = ''; let run = () => {};
var agentStdout = ''; function test(extraArgs, stdoutPattern) {
var needToSpawnAgent = true; const next = run;
var needToExit = true; run = () => {
var procStdout = '';
const procArgs = [`--debug-brk=${common.PORT}`, '-e', '0']; var procStderr = '';
const proc = spawn(process.execPath, procArgs); var agentStdout = '';
proc.stderr.setEncoding('utf8'); var debuggerListening = false;
var outputMatched = false;
const exitAll = common.mustCall((processes) => { var needToSpawnAgent = true;
processes.forEach((myProcess) => { myProcess.kill(); }); var needToExit = true;
});
const procArgs = [`--debug-brk=${common.PORT}`].concat(extraArgs);
proc.stderr.on('data', (chunk) => { const proc = spawn(process.execPath, procArgs);
procStderr += chunk; proc.stderr.setEncoding('utf8');
if (/Debugger listening on/.test(procStderr) && needToSpawnAgent) {
needToSpawnAgent = false; const tryStartAgent = () => {
const agentArgs = ['debug', `localhost:${common.PORT}`]; if (debuggerListening && outputMatched && needToSpawnAgent) {
const agent = spawn(process.execPath, agentArgs); needToSpawnAgent = false;
agent.stdout.setEncoding('utf8'); const agentArgs = ['debug', `localhost:${common.PORT}`];
const agent = spawn(process.execPath, agentArgs);
agent.stdout.on('data', (chunk) => { agent.stdout.setEncoding('utf8');
agentStdout += chunk;
if (/connecting to .+ ok/.test(agentStdout) && needToExit) { agent.stdout.on('data', (chunk) => {
needToExit = false; agentStdout += chunk;
exitAll([proc, agent]); if (/connecting to .+ ok/.test(agentStdout) && needToExit) {
needToExit = false;
exitAll([proc, agent]);
}
});
} }
};
const exitAll = common.mustCall((processes) => {
processes.forEach((myProcess) => { myProcess.kill(); });
}); });
}
}); if (stdoutPattern != null) {
proc.stdout.on('data', (chunk) => {
procStdout += chunk;
outputMatched = outputMatched || stdoutPattern.test(procStdout);
tryStartAgent();
});
} else {
outputMatched = true;
}
proc.stderr.on('data', (chunk) => {
procStderr += chunk;
debuggerListening = debuggerListening ||
/Debugger listening on/.test(procStderr);
tryStartAgent();
});
proc.on('exit', () => {
next();
});
};
}
test(['-e', '0']);
test(['-e', '0', 'foo']);
test(['-p', 'process.argv[1]', 'foo'], /^\s*foo\s*$/);
run();

Loading…
Cancel
Save