Skip to content

Commit 2184e77

Browse files
bnoordhuisrvagg
authored andcommitted
debugger: propagate --debug-port= to debuggee
Before this commit `node --debug-port=1234 debug t.js` ignored the --debug-port= argument, binding to the default port 5858 instead, making it impossible to debug more than one process on the same machine that way. This commit also reduces the number of places where the default port is hard-coded by one. Fixes: #3345 PR-URL: #3470 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bf3afce commit 2184e77

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/_debugger.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.start = function(argv, stdin, stdout) {
2626
stdin = stdin || process.stdin;
2727
stdout = stdout || process.stdout;
2828

29-
const args = ['--debug-brk'].concat(argv);
29+
const args = [`--debug-brk=${exports.port}`].concat(argv);
3030
const interface_ = new Interface(stdin, stdout, args);
3131

3232
stdin.resume();
@@ -41,7 +41,7 @@ exports.start = function(argv, stdin, stdout) {
4141
});
4242
};
4343

44-
exports.port = 5858;
44+
exports.port = process.debugPort;
4545

4646

4747
//
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const path = require('path');
6+
const spawn = require('child_process').spawn;
7+
8+
const children = [];
9+
for (let i = 0; i < 4; i += 1) {
10+
const port = common.PORT + i;
11+
const args = [`--debug-port=${port}`, '--interactive', 'debug', __filename];
12+
const child = spawn(process.execPath, args, { stdio: 'pipe' });
13+
child.test = { port: port, stdout: '' };
14+
child.stdout.setEncoding('utf8');
15+
child.stdout.on('data', function(s) { child.test.stdout += s; update(); });
16+
child.stdout.pipe(process.stdout);
17+
child.stderr.pipe(process.stderr);
18+
children.push(child);
19+
}
20+
21+
function update() {
22+
// Debugger prints relative paths except on Windows.
23+
const filename = path.basename(__filename);
24+
25+
let ready = 0;
26+
for (const child of children)
27+
ready += RegExp(`break in .*?${filename}:1`).test(child.test.stdout);
28+
29+
if (ready === children.length)
30+
for (const child of children)
31+
child.kill();
32+
}
33+
34+
process.on('exit', function() {
35+
for (const child of children) {
36+
const one = RegExp(`Debugger listening on port ${child.test.port}`);
37+
const two = RegExp(`connecting to 127.0.0.1:${child.test.port}`);
38+
assert(one.test(child.test.stdout));
39+
assert(two.test(child.test.stdout));
40+
}
41+
});

0 commit comments

Comments
 (0)