mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 05:00:21 +00:00

`--debug=1.2.3.4:5678` and `--debug=example.com:5678` are now accepted, likewise the `--debug-brk` and `--debug-port` switch. The latter is now something of a misnomer but it's undocumented and for internal use only so it shouldn't matter too much. `--inspect=1.2.3.4:5678` and `--inspect=example.com:5678` are also accepted but don't use the host name yet; they still bind to the default address. Fixes: https://github.com/nodejs/node/issues/3306 PR-URL: https://github.com/nodejs/node/pull/3316 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const spawn = require('child_process').spawn;
|
|
|
|
// FIXME(bnoordhuis) On UNIX platforms, the debugger doesn't reliably kill
|
|
// the inferior when killed by a signal. Work around that by spawning
|
|
// the debugger in its own process group and killing the process group
|
|
// instead of just the debugger process.
|
|
const detached = !common.isWindows;
|
|
|
|
const children = [];
|
|
for (let i = 0; i < 4; i += 1) {
|
|
const port = common.PORT + i;
|
|
const args = [`--debug-port=${port}`, '--interactive', 'debug', __filename];
|
|
const child = spawn(process.execPath, args, { detached, stdio: 'pipe' });
|
|
child.test = { port: port, stdout: '' };
|
|
child.stdout.setEncoding('utf8');
|
|
child.stdout.on('data', function(s) { child.test.stdout += s; update(); });
|
|
child.stdout.pipe(process.stdout);
|
|
child.stderr.pipe(process.stderr);
|
|
children.push(child);
|
|
}
|
|
|
|
function update() {
|
|
// Debugger prints relative paths except on Windows.
|
|
const filename = path.basename(__filename);
|
|
|
|
let ready = 0;
|
|
for (const child of children)
|
|
ready += RegExp(`break in .*?${filename}:1`).test(child.test.stdout);
|
|
|
|
if (ready === children.length)
|
|
for (const child of children)
|
|
kill(child);
|
|
}
|
|
|
|
function kill(child) {
|
|
if (!detached)
|
|
return child.kill();
|
|
|
|
try {
|
|
process.kill(-child.pid); // Kill process group.
|
|
} catch (e) {
|
|
// Generally ESRCH is returned when the process group is already gone. On
|
|
// some platforms such as OS X it may be EPERM though.
|
|
assert.ok((e.code === 'EPERM') || (e.code === 'ESRCH'));
|
|
}
|
|
}
|
|
|
|
process.on('exit', function() {
|
|
for (const child of children) {
|
|
const port = child.test.port;
|
|
const one = RegExp(`Debugger listening on (\\[::\\]|0\.0\.0\.0):${port}`);
|
|
const two = RegExp(`connecting to 127.0.0.1:${port}`);
|
|
assert(one.test(child.test.stdout));
|
|
assert(two.test(child.test.stdout));
|
|
}
|
|
});
|