-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
c1ffb9f
commit 18fb4f9
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const spawn = require('child_process').spawn; | ||
|
||
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, { 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) | ||
child.kill(); | ||
} | ||
|
||
process.on('exit', function() { | ||
for (const child of children) { | ||
const one = RegExp(`Debugger listening on port ${child.test.port}`); | ||
const two = RegExp(`connecting to 127.0.0.1:${child.test.port}`); | ||
assert(one.test(child.test.stdout)); | ||
assert(two.test(child.test.stdout)); | ||
} | ||
}); |