Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspector: make debug an alias for inspect #11441

Merged
merged 2 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions deps/node-inspect/lib/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ function getDefaultPort() {

function runScript(script, scriptArgs, inspectPort, childPrint) {
return new Promise((resolve) => {
const args = [
'--inspect',
`--debug-brk=${inspectPort}`,
].concat([script], scriptArgs);
const needDebugBrk = process.version.match(/^v(6|7)\./);
const args = (needDebugBrk ?
['--inspect', `--debug-brk=${inspectPort}`] :
[`--inspect-brk=${inspectPort}`])
.concat([script], scriptArgs);
const child = spawn(process.execPath, args);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
Expand Down
8 changes: 8 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,14 @@ deprecated.
*Note*: `OutgoingMessage.prototype._renderHeaders` was never documented as
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_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
Expand Down
10 changes: 6 additions & 4 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@
NativeModule.require('_third_party_main');
});

} else if (process.argv[1] === 'debug') {
// Start the debugger agent
NativeModule.require('_debugger').start();
} else if (process.argv[1] === 'inspect' || process.argv[1] === 'debug') {
if (process.argv[1] === 'debug') {
process.emitWarning(
'`node debug` is deprecated. Please use `node inspect` instead.',
'DeprecationWarning', 'DEP0068');
}

} else if (process.argv[1] === 'inspect') {
// Start the debugger agent
process.nextTick(function() {
NativeModule.require('node-inspect/lib/_inspect').start();
Expand Down
4 changes: 2 additions & 2 deletions src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ void PrintDebuggerReadyMessage(const std::string& host,
return;
}
fprintf(out,
"Debugger listening on port %d.\n"
"Debugger listening on %s:%d.\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be best to defer to #11207 for changes to the hint text, although I agree we should include the host.

Copy link
Contributor Author

@ofrobots ofrobots Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do need the change here for the tests to work correctly. I suspect the last one to land will need to resolve some merge conflicts.

"Warning: This is an experimental feature "
"and could change at any time.\n",
port);
host.c_str(), port);
if (ids.size() == 1)
fprintf(out, "To start debugging, open the following URL in Chrome:\n");
if (ids.size() > 1)
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,7 @@ static void PrintHelp() {
// XXX: If you add an option here, please also add it to doc/node.1 and
// doc/api/cli.md
printf("Usage: node [options] [ -e script | script.js ] [arguments]\n"
" node debug script.js [arguments]\n"
" node inspect script.js [arguments]\n"
"\n"
"Options:\n"
" -v, --version print Node.js version\n"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ exports.startNodeForInspectorTest = function(callback,
clearTimeout(timeoutId);
console.log('[err]', text);
if (found) return;
const match = text.match(/Debugger listening on port (\d+)/);
const match = text.match(/Debugger listening on .*:(\d+)/);
found = true;
child.stderr.removeListener('data', dataCallback);
assert.ok(match, text);
Expand Down
14 changes: 9 additions & 5 deletions test/parallel/test-debug-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ const spawn = require('child_process').spawn;
const child = spawn(process.execPath, ['debug']);
child.stderr.setEncoding('utf8');

const expectedUsageMessage = `Usage: node debug script.js
node debug <host>:<port>
node debug -p <pid>
`;
const expectedLines = [
/^\(node:\d+\) \[DEP0068\] DeprecationWarning:/,
/^Usage: .*node.* debug script\.js$/,
/^ .*node.* debug <host>:<port>$/
];

let actualUsageMessage = '';
child.stderr.on('data', function(data) {
actualUsageMessage += data.toString();
});

child.on('exit', common.mustCall(function(code) {
const outputLines = actualUsageMessage.split('\n');
assert.strictEqual(code, 1);
assert.strictEqual(actualUsageMessage, expectedUsageMessage);
for (let i = 0; i < expectedLines.length; i++)
assert(expectedLines[i].test(outputLines[i]));
}));
12 changes: 7 additions & 5 deletions test/parallel/test-debugger-repeat-last.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ proc.stdout.setEncoding('utf8');
let stdout = '';

let sentCommand = false;
let sentEmpty = false;
let sentExit = false;

proc.stdout.on('data', (data) => {
stdout += data;
if (!sentCommand && stdout.includes('> 1')) {

// Send 'n' as the first step.
if (!sentCommand && stdout.includes('> 1 ')) {
setImmediate(() => { proc.stdin.write('n\n'); });
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'); });
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);
return sentExit = true;
}
Expand Down