Skip to content

Commit 74a5e91

Browse files
bnoordhuisMyles Borins
authored and
Myles Borins
committed
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 e3f9bc8 commit 74a5e91

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
@@ -25,7 +25,7 @@ exports.start = function(argv, stdin, stdout) {
2525
stdin = stdin || process.stdin;
2626
stdout = stdout || process.stdout;
2727

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

3131
stdin.resume();
@@ -40,7 +40,7 @@ exports.start = function(argv, stdin, stdout) {
4040
});
4141
};
4242

43-
exports.port = 5858;
43+
exports.port = process.debugPort;
4444

4545

4646
//
+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)