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: add --inspect-brk flag #8979

Merged
merged 1 commit into from
Jan 3, 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
6 changes: 6 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3480,6 +3480,12 @@ static void PrintHelp() {
" 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"
Copy link
Contributor

Choose a reason for hiding this comment

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

--inspect-port was omitted from the docs, see #12581

#endif
" --no-deprecation silence deprecation warnings\n"
" --trace-deprecation show stack traces on deprecations\n"
" --throw-deprecation throw an exception on deprecations\n"
Expand Down
36 changes: 22 additions & 14 deletions src/node_debug_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ int parse_and_validate_port(const std::string& port) {
}

std::pair<std::string, int> 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};
Expand All @@ -46,6 +47,7 @@ std::pair<std::string, int> 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)));
}
Expand Down Expand Up @@ -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") {
Expand All @@ -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;
}

Expand All @@ -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<std::string, int> 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<std::string, int> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions test/sequential/test-debugger-debug-brk.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ function test(arg) {

test('--debug-brk');
test('--debug-brk=5959');
test('--inspect-brk');
test('--inspect-brk=9230');