| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,6 +65,20 @@ | |||
| 65 | 65 | }); | |
| 66 | 66 | process.argv[0] = process.execPath; | |
| 67 | 67 | ||
| 68 | + // Handle `--debug*` deprecation and invalidation | ||
| 69 | + if (process._invalidDebug) { | ||
| 70 | + process.emitWarning( | ||
| 71 | + '`node --debug` and `node --debug-brk` are invalid. ' + | ||
| 72 | + 'Please use `node --inspect` or `node --inspect-brk` instead.', | ||
| 73 | + 'DeprecationWarning', 'DEP0062', startup, true); | ||
| 74 | + process.exit(9); | ||
| 75 | + } else if (process._deprecatedDebugBrk) { | ||
| 76 | + process.emitWarning( | ||
| 77 | + '`node --inspect --debug-brk` is deprecated. ' + | ||
| 78 | + 'Please use `node --inspect-brk` instead.', | ||
| 79 | + 'DeprecationWarning', 'DEP0062', startup, true); | ||
| 80 | + } | ||
| 81 | + | ||
| 68 | 82 | // There are various modes that Node can run in. The most common two | |
| 69 | 83 | // are running from a script and running the REPL - but there are a few | |
| 70 | 84 | // others like the debugger or running --eval arguments. Here we decide | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,7 +111,7 @@ function setupProcessWarnings() { | |||
| 111 | 111 | // process.emitWarning(error) | |
| 112 | 112 | // process.emitWarning(str[, type[, code]][, ctor]) | |
| 113 | 113 | // process.emitWarning(str[, options]) | |
| 114 | - process.emitWarning = function(warning, type, code, ctor) { | ||
| 114 | + process.emitWarning = function(warning, type, code, ctor, now) { | ||
| 115 | 115 | const errors = lazyErrors(); | |
| 116 | 116 | var detail; | |
| 117 | 117 | if (type !== null && typeof type === 'object' && !Array.isArray(type)) { | |
@@ -150,6 +150,7 @@ function setupProcessWarnings() { | |||
| 150 | 150 | if (process.throwDeprecation) | |
| 151 | 151 | throw warning; | |
| 152 | 152 | } | |
| 153 | - process.nextTick(doEmitWarning(warning)); | ||
| 153 | + if (now) process.emit('warning', warning); | ||
| 154 | + else process.nextTick(doEmitWarning(warning)); | ||
| 154 | 155 | }; | |
| 155 | 156 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -537,7 +537,7 @@ Module.prototype._compile = function(content, filename) { | |||
| 537 | 537 | }); | |
| 538 | 538 | ||
| 539 | 539 | var inspectorWrapper = null; | |
| 540 | - if (process._debugWaitConnect && process._eval == null) { | ||
| 540 | + if (process._breakFirstLine && process._eval == null) { | ||
| 541 | 541 | if (!resolvedArgv) { | |
| 542 | 542 | // we enter the repl if we're not given a filename argument. | |
| 543 | 543 | if (process.argv[1]) { | |
@@ -549,7 +549,7 @@ Module.prototype._compile = function(content, filename) { | |||
| 549 | 549 | ||
| 550 | 550 | // Set breakpoint on module start | |
| 551 | 551 | if (filename === resolvedArgv) { | |
| 552 | - delete process._debugWaitConnect; | ||
| 552 | + delete process._breakFirstLine; | ||
| 553 | 553 | inspectorWrapper = process.binding('inspector').callAndPauseOnStart; | |
| 554 | 554 | if (!inspectorWrapper) { | |
| 555 | 555 | const Debug = vm.runInDebugContext('Debug'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3391,9 +3391,29 @@ void SetupProcessObject(Environment* env, | |||
| 3391 | 3391 | READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate())); | |
| 3392 | 3392 | } | |
| 3393 | 3393 | ||
| 3394 | + // TODO(refack): move the following 4 to `node_config` | ||
| 3395 | + // --inspect | ||
| 3396 | + if (debug_options.inspector_enabled()) { | ||
| 3397 | + READONLY_DONT_ENUM_PROPERTY(process, | ||
| 3398 | + "_inspectorEnbale", True(env->isolate())); | ||
| 3399 | + } | ||
| 3400 | + | ||
| 3394 | 3401 | // --inspect-brk | |
| 3395 | 3402 | if (debug_options.wait_for_connect()) { | |
| 3396 | - READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate())); | ||
| 3403 | + READONLY_DONT_ENUM_PROPERTY(process, | ||
| 3404 | + "_breakFirstLine", True(env->isolate())); | ||
| 3405 | + } | ||
| 3406 | + | ||
| 3407 | + // --inspect --debug-brk | ||
| 3408 | + if (debug_options.deprecated_invocation()) { | ||
| 3409 | + READONLY_DONT_ENUM_PROPERTY(process, | ||
| 3410 | + "_deprecatedDebugBrk", True(env->isolate())); | ||
| 3411 | + } | ||
| 3412 | + | ||
| 3413 | + // --debug or, --debug-brk without --inspect | ||
| 3414 | + if (debug_options.invalid_invocation()) { | ||
| 3415 | + READONLY_DONT_ENUM_PROPERTY(process, | ||
| 3416 | + "_invalidDebug", True(env->isolate())); | ||
| 3397 | 3417 | } | |
| 3398 | 3418 | ||
| 3399 | 3419 | // --security-revert flags | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,9 +8,7 @@ | |||
| 8 | 8 | namespace node { | |
| 9 | 9 | ||
| 10 | 10 | namespace { | |
| 11 | - #if HAVE_INSPECTOR | ||
| 12 | 11 | const int default_inspector_port = 9229; | |
| 13 | - #endif // HAVE_INSPECTOR | ||
| 14 | 12 | ||
| 15 | 13 | inline std::string remove_brackets(const std::string& host) { | |
| 16 | 14 | if (!host.empty() && host.front() == '[' && host.back() == ']') | |
@@ -56,14 +54,12 @@ std::pair<std::string, int> split_host_port(const std::string& arg) { | |||
| 56 | 54 | } // namespace | |
| 57 | 55 | ||
| 58 | 56 | DebugOptions::DebugOptions() : | |
| 59 | - #if HAVE_INSPECTOR | ||
| 60 | 57 | inspector_enabled_(false), | |
| 61 | - #endif // HAVE_INSPECTOR | ||
| 62 | - wait_connect_(false), http_enabled_(false), | ||
| 58 | + deprecated_debug_(false), | ||
| 59 | + break_first_line_(false), | ||
| 63 | 60 | host_name_("127.0.0.1"), port_(-1) { } | |
| 64 | 61 | ||
| 65 | 62 | bool DebugOptions::ParseOption(const char* argv0, const std::string& option) { | |
| 66 | - bool enable_inspector = false; | ||
| 67 | 63 | bool has_argument = false; | |
| 68 | 64 | std::string option_name; | |
| 69 | 65 | std::string argument; | |
@@ -81,11 +77,21 @@ bool DebugOptions::ParseOption(const char* argv0, const std::string& option) { | |||
| 81 | 77 | argument.clear(); | |
| 82 | 78 | } | |
| 83 | 79 | ||
| 80 | + // Note that --debug-port and --debug-brk in conjuction with --inspect | ||
| 81 | + // work but are undocumented. | ||
| 82 | + // --debug is no longer valid. | ||
| 83 | + // Ref: https://github.com/nodejs/node/issues/12630 | ||
| 84 | + // Ref: https://github.com/nodejs/node/pull/12949 | ||
| 84 | 85 | if (option_name == "--inspect") { | |
| 85 | - enable_inspector = true; | ||
| 86 | + inspector_enabled_ = true; | ||
| 87 | + } else if (option_name == "--debug") { | ||
| 88 | + deprecated_debug_ = true; | ||
| 86 | 89 | } else if (option_name == "--inspect-brk") { | |
| 87 | - enable_inspector = true; | ||
| 88 | - wait_connect_ = true; | ||
| 90 | + inspector_enabled_ = true; | ||
| 91 | + break_first_line_ = true; | ||
| 92 | + } else if (option_name == "--debug-brk") { | ||
| 93 | + break_first_line_ = true; | ||
| 94 | + deprecated_debug_ = true; | ||
| 89 | 95 | } else if (option_name == "--debug-port" || | |
| 90 | 96 | option_name == "--inspect-port") { | |
| 91 | 97 | if (!has_argument) { | |
@@ -97,15 +103,14 @@ bool DebugOptions::ParseOption(const char* argv0, const std::string& option) { | |||
| 97 | 103 | return false; | |
| 98 | 104 | } | |
| 99 | 105 | ||
| 100 | - if (enable_inspector) { | ||
| 101 | - #if HAVE_INSPECTOR | ||
| 102 | - inspector_enabled_ = true; | ||
| 103 | - #else | ||
| 106 | + #if !HAVE_INSPECTOR | ||
| 107 | + if (inspector_enabled_) { | ||
| 104 | 108 | fprintf(stderr, | |
| 105 | 109 | "Inspector support is not available with this Node.js build\n"); | |
| 106 | - return false; | ||
| 107 | - #endif | ||
| 108 | 110 | } | |
| 111 | + inspector_enabled_ = false; | ||
| 112 | + return false; | ||
| 113 | + #endif | ||
| 109 | 114 | ||
| 110 | 115 | // argument can be specified for *any* option to specify host:port | |
| 111 | 116 | if (has_argument) { | |
@@ -124,9 +129,7 @@ bool DebugOptions::ParseOption(const char* argv0, const std::string& option) { | |||
| 124 | 129 | int DebugOptions::port() const { | |
| 125 | 130 | int port = port_; | |
| 126 | 131 | if (port < 0) { | |
| 127 | - #if HAVE_INSPECTOR | ||
| 128 | 132 | port = default_inspector_port; | |
| 129 | - #endif // HAVE_INSPECTOR | ||
| 130 | 133 | } | |
| 131 | 134 | return port; | |
| 132 | 135 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,25 +10,24 @@ class DebugOptions { | |||
| 10 | 10 | public: | |
| 11 | 11 | DebugOptions(); | |
| 12 | 12 | bool ParseOption(const char* argv0, const std::string& option); | |
| 13 | - bool inspector_enabled() const { | ||
| 14 | - #if HAVE_INSPECTOR | ||
| 15 | - return inspector_enabled_; | ||
| 16 | - #else | ||
| 17 | - return false; | ||
| 18 | - #endif // HAVE_INSPECTOR | ||
| 13 | + bool inspector_enabled() const { return inspector_enabled_; } | ||
| 14 | + bool deprecated_invocation() const { | ||
| 15 | + return deprecated_debug_ && | ||
| 16 | + inspector_enabled_ && | ||
| 17 | + break_first_line_; | ||
| 19 | 18 | } | |
| 20 | - bool ToolsServerEnabled(); | ||
| 21 | - bool wait_for_connect() const { return wait_connect_; } | ||
| 19 | + bool invalid_invocation() const { | ||
| 20 | + return deprecated_debug_ && !inspector_enabled_; | ||
| 21 | + } | ||
| 22 | + bool wait_for_connect() const { return break_first_line_; } | ||
| 22 | 23 | std::string host_name() const { return host_name_; } | |
| 23 | 24 | int port() const; | |
| 24 | 25 | void set_port(int port) { port_ = port; } | |
| 25 | 26 | ||
| 26 | 27 | private: | |
| 27 | - #if HAVE_INSPECTOR | ||
| 28 | 28 | bool inspector_enabled_; | |
| 29 | - #endif // HAVE_INSPECTOR | ||
| 30 | - bool wait_connect_; | ||
| 31 | - bool http_enabled_; | ||
| 29 | + bool deprecated_debug_; | ||
| 30 | + bool break_first_line_; | ||
| 32 | 31 | std::string host_name_; | |
| 33 | 32 | int port_; | |
| 34 | 33 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -496,9 +496,9 @@ Harness.prototype.kill = function() { | |||
| 496 | 496 | }; | |
| 497 | 497 | ||
| 498 | 498 | exports.startNodeForInspectorTest = function(callback, | |
| 499 | - inspectorFlag = '--inspect-brk', | ||
| 499 | + inspectorFlags = ['--inspect-brk'], | ||
| 500 | 500 | opt_script_contents) { | |
| 501 | - const args = [inspectorFlag]; | ||
| 501 | + const args = [].concat(inspectorFlags); | ||
| 502 | 502 | if (opt_script_contents) { | |
| 503 | 503 | args.push('-e', opt_script_contents); | |
| 504 | 504 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,57 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + common.skipIfInspectorDisabled(); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const helper = require('./inspector-helper.js'); | ||
| 6 | + | ||
| 7 | + function setupExpectBreakOnLine(line, url, session, scopeIdCallback) { | ||
| 8 | + return function(message) { | ||
| 9 | + if ('Debugger.paused' === message['method']) { | ||
| 10 | + const callFrame = message['params']['callFrames'][0]; | ||
| 11 | + const location = callFrame['location']; | ||
| 12 | + assert.strictEqual(url, session.scriptUrlForId(location['scriptId'])); | ||
| 13 | + assert.strictEqual(line, location['lineNumber']); | ||
| 14 | + scopeIdCallback && | ||
| 15 | + scopeIdCallback(callFrame['scopeChain'][0]['object']['objectId']); | ||
| 16 | + return true; | ||
| 17 | + } | ||
| 18 | + }; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + function testBreakpointOnStart(session) { | ||
| 22 | + const commands = [ | ||
| 23 | + { 'method': 'Runtime.enable' }, | ||
| 24 | + { 'method': 'Debugger.enable' }, | ||
| 25 | + { 'method': 'Debugger.setPauseOnExceptions', | ||
| 26 | + 'params': {'state': 'none'} }, | ||
| 27 | + { 'method': 'Debugger.setAsyncCallStackDepth', | ||
| 28 | + 'params': {'maxDepth': 0} }, | ||
| 29 | + { 'method': 'Profiler.enable' }, | ||
| 30 | + { 'method': 'Profiler.setSamplingInterval', | ||
| 31 | + 'params': {'interval': 100} }, | ||
| 32 | + { 'method': 'Debugger.setBlackboxPatterns', | ||
| 33 | + 'params': {'patterns': []} }, | ||
| 34 | + { 'method': 'Runtime.runIfWaitingForDebugger' } | ||
| 35 | + ]; | ||
| 36 | + | ||
| 37 | + session | ||
| 38 | + .sendInspectorCommands(commands) | ||
| 39 | + .expectMessages(setupExpectBreakOnLine(0, session.mainScriptPath, session)); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + function testWaitsForFrontendDisconnect(session, harness) { | ||
| 43 | + console.log('[test]', 'Verify node waits for the frontend to disconnect'); | ||
| 44 | + session.sendInspectorCommands({ 'method': 'Debugger.resume'}) | ||
| 45 | + .expectStderrOutput('Waiting for the debugger to disconnect...') | ||
| 46 | + .disconnect(true); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + function runTests(harness) { | ||
| 50 | + harness | ||
| 51 | + .runFrontendSession([ | ||
| 52 | + testBreakpointOnStart, | ||
| 53 | + testWaitsForFrontendDisconnect | ||
| 54 | + ]).expectShutDown(55); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + helper.startNodeForInspectorTest(runTests, ['--inspect', '--debug-brk']); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,23 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const assert = require('assert'); | ||
| 3 | + const execFile = require('child_process').execFile; | ||
| 4 | + const path = require('path'); | ||
| 5 | + | ||
| 6 | + const common = require('../common'); | ||
| 7 | + common.skipIfInspectorDisabled(); | ||
| 8 | + | ||
| 9 | + const mainScript = path.join(common.fixturesDir, 'loop.js'); | ||
| 10 | + const expected = | ||
| 11 | + '`node --debug` and `node --debug-brk` are invalid. ' + | ||
| 12 | + 'Please use `node --inspect` or `node --inspect-brk` instead.'; | ||
| 13 | + for (const invalidArg of ['--debug-brk', '--debug']) { | ||
| 14 | + execFile( | ||
| 15 | + process.execPath, | ||
| 16 | + [ invalidArg, mainScript ], | ||
| 17 | + common.mustCall((error, stdout, stderr) => { | ||
| 18 | + assert.strictEqual(error.code, 9, `node ${invalidArg} should exit 9`); | ||
| 19 | + assert.strictEqual(stderr.includes(expected), true, | ||
| 20 | + `${stderr} should include '${expected}'`); | ||
| 21 | + }) | ||
| 22 | + ); | ||
| 23 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + common.skipIfInspectorDisabled(); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const spawn = require('child_process').spawn; | ||
| 6 | + | ||
| 7 | + const script = common.fixturesDir + '/empty.js'; | ||
| 8 | + | ||
| 9 | + function test(arg) { | ||
| 10 | + const child = spawn(process.execPath, ['--inspect', arg, script]); | ||
| 11 | + const argStr = child.spawnargs.join(' '); | ||
| 12 | + const fail = () => assert.fail(true, false, `'${argStr}' should not quit`); | ||
| 13 | + child.on('exit', fail); | ||
| 14 | + | ||
| 15 | + // give node time to start up the debugger | ||
| 16 | + setTimeout(function() { | ||
| 17 | + child.removeListener('exit', fail); | ||
| 18 | + child.kill(); | ||
| 19 | + }, 2000); | ||
| 20 | + | ||
| 21 | + process.on('exit', function() { | ||
| 22 | + assert(child.killed); | ||
| 23 | + }); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + test('--debug-brk'); | ||
| 27 | + test('--debug-brk=5959'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments