From b7608ac7077f95837c3b9eefdfd04c45b66179fa Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Thu, 6 Apr 2017 10:40:55 -0700 Subject: [PATCH 1/2] deps: cherry-pick node-inspect#43 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node 8.x no longer has --debug-brk. Ref: https://github.com/nodejs/node-inspect/pull/43 PR-URL: https://github.com/nodejs/node/pull/11441 Reviewed-By: bnoordhuis - Ben Noordhuis Reviewed-By: joshgav - Josh Gavant Reviewed-By: cjihrig - Colin Ihrig Reviewed-By: targos - Michaël Zasso --- deps/node-inspect/lib/_inspect.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/deps/node-inspect/lib/_inspect.js b/deps/node-inspect/lib/_inspect.js index ac32e0a6a432fa..7c13ef786e3073 100644 --- a/deps/node-inspect/lib/_inspect.js +++ b/deps/node-inspect/lib/_inspect.js @@ -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'); From a235ccd1685b96089ca2e8c175bb39e1ef59afbd Mon Sep 17 00:00:00 2001 From: Ali Ijaz Sheikh Date: Tue, 14 Mar 2017 14:20:38 -0700 Subject: [PATCH 2/2] src,test: debug is now an alias for inspect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 Reviewed-By: joshgav - Josh Gavant Reviewed-By: cjihrig - Colin Ihrig Reviewed-By: targos - Michaël Zasso --- doc/api/deprecations.md | 8 ++++++++ lib/internal/bootstrap_node.js | 10 ++++++---- src/inspector_socket_server.cc | 4 ++-- src/node.cc | 2 +- test/{parallel => disabled}/test-debugger-pid.js | 0 test/inspector/inspector-helper.js | 2 +- test/parallel/test-debug-usage.js | 14 +++++++++----- test/parallel/test-debugger-repeat-last.js | 12 +++++++----- 8 files changed, 34 insertions(+), 18 deletions(-) rename test/{parallel => disabled}/test-debugger-pid.js (100%) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 8de386118af960..8461caabfc56ee 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -582,6 +582,14 @@ deprecated. *Note*: `OutgoingMessage.prototype._renderHeaders` was never documented as an officially supported API. + +### 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 diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index b4ed16573e1e07..cb6867125860e1 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -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(); diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc index 1c8fa70b65a3b3..07efed4972aaef 100644 --- a/src/inspector_socket_server.cc +++ b/src/inspector_socket_server.cc @@ -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" "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) diff --git a/src/node.cc b/src/node.cc index 5b5be22bf3b3f7..9636edece02573 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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" diff --git a/test/parallel/test-debugger-pid.js b/test/disabled/test-debugger-pid.js similarity index 100% rename from test/parallel/test-debugger-pid.js rename to test/disabled/test-debugger-pid.js diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index 004f4f93e4c309..8ab4ce39d78162 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -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); diff --git a/test/parallel/test-debug-usage.js b/test/parallel/test-debug-usage.js index 67ee08ce729431..53967661a6dcaa 100644 --- a/test/parallel/test-debug-usage.js +++ b/test/parallel/test-debug-usage.js @@ -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 : - node debug -p -`; +const expectedLines = [ + /^\(node:\d+\) \[DEP0068\] DeprecationWarning:/, + /^Usage: .*node.* debug script\.js$/, + /^ .*node.* debug :$/ +]; + 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])); })); diff --git a/test/parallel/test-debugger-repeat-last.js b/test/parallel/test-debugger-repeat-last.js index cacedbbd7c6e99..9d1dd4754d65d5 100644 --- a/test/parallel/test-debugger-repeat-last.js +++ b/test/parallel/test-debugger-repeat-last.js @@ -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; }