From 0b64f7fc0ed95cedc80340fd370cd482f9f52cc2 Mon Sep 17 00:00:00 2001 From: Josh Gavant Date: Fri, 3 Feb 2017 09:36:30 -0800 Subject: [PATCH] src, inspector: add --inspect-brk add an --inspect-brk option which breaks on first line of user script. same behavior as old --debug-brk flag. PR-URL: https://github.com/nodejs/node/pull/11149 Reviewed-By: Eugene Ostroukhov Reviewed-By: James M Snell --- src/node.cc | 40 ++++++++++++++-------- src/node_debug_options.cc | 36 +++++++++++-------- test/inspector/inspector-helper.js | 2 +- test/sequential/test-debugger-debug-brk.js | 2 ++ 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/node.cc b/src/node.cc index 2c5540fdb3d00c..21d304cd539f11 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3471,21 +3471,31 @@ static void PrintHelp() { " node debug script.js [arguments] \n" "\n" "Options:\n" - " -v, --version print Node.js version\n" - " -e, --eval script evaluate script\n" - " -p, --print evaluate script and print result\n" - " -c, --check syntax check script without executing\n" - " -i, --interactive always enter the REPL even if stdin\n" - " does not appear to be a terminal\n" - " -r, --require module to preload (option can be repeated)\n" - " --no-deprecation silence deprecation warnings\n" - " --trace-deprecation show stack traces on deprecations\n" - " --throw-deprecation throw an exception on deprecations\n" - " --no-warnings silence all process warnings\n" - " --trace-warnings show stack traces on process warnings\n" - " --trace-sync-io show stack trace when use of sync IO\n" - " is detected after the first tick\n" - " --track-heap-objects track heap object allocations for heap " + " -v, --version print Node.js version\n" + " -e, --eval script evaluate script\n" + " -p, --print evaluate script and print result\n" + " -c, --check syntax check script without executing\n" + " -i, --interactive always enter the REPL even if stdin\n" + " does not appear to be a terminal\n" + " -r, --require module to preload (option can be " + "repeated)\n" +#if HAVE_INSPECTOR + " --inspect[=host:port] activate inspector on host:port\n" + " (default: 127.0.0.1:9229)\n" + " --inspect-brk[=host:port] activate inspector on host:port\n" + " and break at start of user script\n" +#endif + " --no-deprecation silence deprecation warnings\n" + " --trace-deprecation show stack traces on deprecations\n" + " --throw-deprecation throw an exception on deprecations\n" + " --no-warnings silence all process warnings\n" + " --trace-warnings show stack traces on process warnings\n" + " --trace-sync-io show stack trace when use of sync IO\n" + " is detected after the first tick\n" + " --trace-events-enabled track trace events\n" + " --trace-event-categories comma separated list of trace event\n" + " categories to record\n" + " --track-heap-objects track heap object allocations for heap " "snapshots\n" " --prof-process process v8 profiler output generated\n" " using --prof\n" diff --git a/src/node_debug_options.cc b/src/node_debug_options.cc index 5681e3d46edaca..410e23acb3101b 100644 --- a/src/node_debug_options.cc +++ b/src/node_debug_options.cc @@ -30,7 +30,8 @@ int parse_and_validate_port(const std::string& port) { } std::pair split_host_port(const std::string& arg) { - // IPv6, no port + // remove_brackets only works if no port is specified + // so if it has an effect only an IPv6 address was specified std::string host = remove_brackets(arg); if (host.length() < arg.length()) return {host, -1}; @@ -46,6 +47,7 @@ std::pair split_host_port(const std::string& arg) { } return {"", parse_and_validate_port(arg)}; } + // host and port found return std::make_pair(remove_brackets(arg.substr(0, colon)), parse_and_validate_port(arg.substr(colon + 1))); } @@ -90,6 +92,7 @@ bool DebugOptions::ParseOption(const std::string& option) { argument = option.substr(pos + 1); } + // --debug and --inspect are mutually exclusive if (option_name == "--debug") { debugger_enabled_ = true; } else if (option_name == "--debug-brk") { @@ -98,7 +101,15 @@ bool DebugOptions::ParseOption(const std::string& option) { } else if (option_name == "--inspect") { debugger_enabled_ = true; enable_inspector = true; - } else if (option_name != "--debug-port" || !has_argument) { + } else if (option_name == "--inspect-brk") { + debugger_enabled_ = true; + enable_inspector = true; + wait_connect_ = true; + } else if ((option_name != "--debug-port" && + option_name != "--inspect-port") || + !has_argument) { + // only other valid possibility is --debug-port, + // which requires an argument return false; } @@ -112,20 +123,17 @@ bool DebugOptions::ParseOption(const std::string& option) { #endif } - if (!has_argument) { - return true; + // argument can be specified for *any* option to specify host:port + if (has_argument) { + std::pair host_port = split_host_port(argument); + if (!host_port.first.empty()) { + host_name_ = host_port.first; + } + if (host_port.second >= 0) { + port_ = host_port.second; + } } - // FIXME(bnoordhuis) Move IPv6 address parsing logic to lib/net.js. - // It seems reasonable to support [address]:port notation - // in net.Server#listen() and net.Socket#connect(). - std::pair host_port = split_host_port(argument); - if (!host_port.first.empty()) { - host_name_ = host_port.first; - } - if (host_port.second >= 0) { - port_ = host_port.second; - } return true; } diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index e22ca87dff7858..9db9613184e068 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -428,7 +428,7 @@ Harness.prototype.expectShutDown = function(errorCode) { exports.startNodeForInspectorTest = function(callback) { const child = spawn(process.execPath, - [ '--inspect', '--debug-brk', mainScript ]); + [ '--inspect-brk', mainScript ]); const timeoutId = timeout('Child process did not start properly', 4); diff --git a/test/sequential/test-debugger-debug-brk.js b/test/sequential/test-debugger-debug-brk.js index 26c3418171e8df..f04af4544f88a2 100644 --- a/test/sequential/test-debugger-debug-brk.js +++ b/test/sequential/test-debugger-debug-brk.js @@ -26,3 +26,5 @@ function test(arg) { test('--debug-brk'); test('--debug-brk=5959'); +test('--inspect-brk'); +test('--inspect-brk=9230');