src,test: debug is now an alias for inspect

`node debug` is now an alias of `node inspect`. This is intended to be
a minimal change – it does not get rid of the the debugger code. That
can be done in a follow-on.

PR-URL: https://github.com/nodejs/node/pull/11441
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: joshgav - Josh Gavant <josh.gavant@outlook.com>
Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com>
This commit is contained in:
Ali Ijaz Sheikh 2017-03-14 14:20:38 -07:00
parent b7608ac707
commit a235ccd168
8 changed files with 34 additions and 18 deletions

View File

@ -582,6 +582,14 @@ deprecated.
*Note*: `OutgoingMessage.prototype._renderHeaders` was never documented as *Note*: `OutgoingMessage.prototype._renderHeaders` was never documented as
an officially supported API. an officially supported API.
<a id="DEP0068"></a>
### DEP0068: node debug
Type: Runtime
`node debug` corresponds to the legacy CLI debugger which has been replaced with
a V8-inspector based CLI debugger available through `node inspect`.
[alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding [alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding
[alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size [alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size [`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size

View File

@ -78,11 +78,13 @@
NativeModule.require('_third_party_main'); NativeModule.require('_third_party_main');
}); });
} else if (process.argv[1] === 'debug') { } else if (process.argv[1] === 'inspect' || process.argv[1] === 'debug') {
// Start the debugger agent if (process.argv[1] === 'debug') {
NativeModule.require('_debugger').start(); process.emitWarning(
'`node debug` is deprecated. Please use `node inspect` instead.',
'DeprecationWarning', 'DEP0068');
}
} else if (process.argv[1] === 'inspect') {
// Start the debugger agent // Start the debugger agent
process.nextTick(function() { process.nextTick(function() {
NativeModule.require('node-inspect/lib/_inspect').start(); NativeModule.require('node-inspect/lib/_inspect').start();

View File

@ -82,10 +82,10 @@ void PrintDebuggerReadyMessage(const std::string& host,
return; return;
} }
fprintf(out, fprintf(out,
"Debugger listening on port %d.\n" "Debugger listening on %s:%d.\n"
"Warning: This is an experimental feature " "Warning: This is an experimental feature "
"and could change at any time.\n", "and could change at any time.\n",
port); host.c_str(), port);
if (ids.size() == 1) if (ids.size() == 1)
fprintf(out, "To start debugging, open the following URL in Chrome:\n"); fprintf(out, "To start debugging, open the following URL in Chrome:\n");
if (ids.size() > 1) if (ids.size() > 1)

View File

@ -3525,7 +3525,7 @@ static void PrintHelp() {
// XXX: If you add an option here, please also add it to doc/node.1 and // XXX: If you add an option here, please also add it to doc/node.1 and
// doc/api/cli.md // doc/api/cli.md
printf("Usage: node [options] [ -e script | script.js ] [arguments]\n" printf("Usage: node [options] [ -e script | script.js ] [arguments]\n"
" node debug script.js [arguments]\n" " node inspect script.js [arguments]\n"
"\n" "\n"
"Options:\n" "Options:\n"
" -v, --version print Node.js version\n" " -v, --version print Node.js version\n"

View File

@ -461,7 +461,7 @@ exports.startNodeForInspectorTest = function(callback,
clearTimeout(timeoutId); clearTimeout(timeoutId);
console.log('[err]', text); console.log('[err]', text);
if (found) return; if (found) return;
const match = text.match(/Debugger listening on port (\d+)/); const match = text.match(/Debugger listening on .*:(\d+)/);
found = true; found = true;
child.stderr.removeListener('data', dataCallback); child.stderr.removeListener('data', dataCallback);
assert.ok(match, text); assert.ok(match, text);

View File

@ -6,16 +6,20 @@ const spawn = require('child_process').spawn;
const child = spawn(process.execPath, ['debug']); const child = spawn(process.execPath, ['debug']);
child.stderr.setEncoding('utf8'); child.stderr.setEncoding('utf8');
const expectedUsageMessage = `Usage: node debug script.js const expectedLines = [
node debug <host>:<port> /^\(node:\d+\) \[DEP0068\] DeprecationWarning:/,
node debug -p <pid> /^Usage: .*node.* debug script\.js$/,
`; /^ .*node.* debug <host>:<port>$/
];
let actualUsageMessage = ''; let actualUsageMessage = '';
child.stderr.on('data', function(data) { child.stderr.on('data', function(data) {
actualUsageMessage += data.toString(); actualUsageMessage += data.toString();
}); });
child.on('exit', common.mustCall(function(code) { child.on('exit', common.mustCall(function(code) {
const outputLines = actualUsageMessage.split('\n');
assert.strictEqual(code, 1); assert.strictEqual(code, 1);
assert.strictEqual(actualUsageMessage, expectedUsageMessage); for (let i = 0; i < expectedLines.length; i++)
assert(expectedLines[i].test(outputLines[i]));
})); }));

View File

@ -20,20 +20,22 @@ proc.stdout.setEncoding('utf8');
let stdout = ''; let stdout = '';
let sentCommand = false; let sentCommand = false;
let sentEmpty = false;
let sentExit = false; let sentExit = false;
proc.stdout.on('data', (data) => { proc.stdout.on('data', (data) => {
stdout += data; stdout += data;
// Send 'n' as the first step.
if (!sentCommand && stdout.includes('> 1 ')) { if (!sentCommand && stdout.includes('> 1 ')) {
setImmediate(() => { proc.stdin.write('n\n'); }); setImmediate(() => { proc.stdin.write('n\n'); });
return sentCommand = true; return sentCommand = true;
} }
if (!sentEmpty && stdout.includes('> 3')) { // Send empty (repeat last command) until we reach line 5.
if (sentCommand && !stdout.includes('> 5')) {
setImmediate(() => { proc.stdin.write('\n'); }); setImmediate(() => { proc.stdin.write('\n'); });
return sentEmpty = true; return true;
} }
if (!sentExit && sentCommand && sentEmpty) { if (!sentExit && stdout.includes('> 5')) {
setTimeout(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); }, 1); setTimeout(() => { proc.stdin.write('\n\n\n.exit\n\n\n'); }, 1);
return sentExit = true; return sentExit = true;
} }