Skip to content

Commit 6ff3b03

Browse files
committed
src, inspector: add --inspect-brk option
add an --inspect-brk option which breaks on first line of user script. same behavior as old --debug-brk flag. PR-URL: #8979 Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f5d92f3 commit 6ff3b03

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/node.cc

+6
Original file line numberDiff line numberDiff line change
@@ -3480,6 +3480,12 @@ static void PrintHelp() {
34803480
" does not appear to be a terminal\n"
34813481
" -r, --require module to preload (option can be "
34823482
"repeated)\n"
3483+
#if HAVE_INSPECTOR
3484+
" --inspect[=host:port] activate inspector on host:port\n"
3485+
" (default: 127.0.0.1:9229)\n"
3486+
" --inspect-brk[=host:port] activate inspector on host:port\n"
3487+
" and break at start of user script\n"
3488+
#endif
34833489
" --no-deprecation silence deprecation warnings\n"
34843490
" --trace-deprecation show stack traces on deprecations\n"
34853491
" --throw-deprecation throw an exception on deprecations\n"

src/node_debug_options.cc

+22-14
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int parse_and_validate_port(const std::string& port) {
3030
}
3131

3232
std::pair<std::string, int> split_host_port(const std::string& arg) {
33-
// IPv6, no port
33+
// remove_brackets only works if no port is specified
34+
// so if it has an effect only an IPv6 address was specified
3435
std::string host = remove_brackets(arg);
3536
if (host.length() < arg.length())
3637
return {host, -1};
@@ -46,6 +47,7 @@ std::pair<std::string, int> split_host_port(const std::string& arg) {
4647
}
4748
return {"", parse_and_validate_port(arg)};
4849
}
50+
// host and port found
4951
return std::make_pair(remove_brackets(arg.substr(0, colon)),
5052
parse_and_validate_port(arg.substr(colon + 1)));
5153
}
@@ -90,6 +92,7 @@ bool DebugOptions::ParseOption(const std::string& option) {
9092
argument = option.substr(pos + 1);
9193
}
9294

95+
// --debug and --inspect are mutually exclusive
9396
if (option_name == "--debug") {
9497
debugger_enabled_ = true;
9598
} else if (option_name == "--debug-brk") {
@@ -98,7 +101,15 @@ bool DebugOptions::ParseOption(const std::string& option) {
98101
} else if (option_name == "--inspect") {
99102
debugger_enabled_ = true;
100103
enable_inspector = true;
101-
} else if (option_name != "--debug-port" || !has_argument) {
104+
} else if (option_name == "--inspect-brk") {
105+
debugger_enabled_ = true;
106+
enable_inspector = true;
107+
wait_connect_ = true;
108+
} else if ((option_name != "--debug-port" &&
109+
option_name != "--inspect-port") ||
110+
!has_argument) {
111+
// only other valid possibility is --debug-port,
112+
// which requires an argument
102113
return false;
103114
}
104115

@@ -112,20 +123,17 @@ bool DebugOptions::ParseOption(const std::string& option) {
112123
#endif
113124
}
114125

115-
if (!has_argument) {
116-
return true;
126+
// argument can be specified for *any* option to specify host:port
127+
if (has_argument) {
128+
std::pair<std::string, int> host_port = split_host_port(argument);
129+
if (!host_port.first.empty()) {
130+
host_name_ = host_port.first;
131+
}
132+
if (host_port.second >= 0) {
133+
port_ = host_port.second;
134+
}
117135
}
118136

119-
// FIXME(bnoordhuis) Move IPv6 address parsing logic to lib/net.js.
120-
// It seems reasonable to support [address]:port notation
121-
// in net.Server#listen() and net.Socket#connect().
122-
std::pair<std::string, int> host_port = split_host_port(argument);
123-
if (!host_port.first.empty()) {
124-
host_name_ = host_port.first;
125-
}
126-
if (host_port.second >= 0) {
127-
port_ = host_port.second;
128-
}
129137
return true;
130138
}
131139

test/inspector/inspector-helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Harness.prototype.expectShutDown = function(errorCode) {
428428

429429
exports.startNodeForInspectorTest = function(callback) {
430430
const child = spawn(process.execPath,
431-
[ '--inspect', '--debug-brk', mainScript ]);
431+
[ '--inspect-brk', mainScript ]);
432432

433433
const timeoutId = timeout('Child process did not start properly', 4);
434434

test/sequential/test-debugger-debug-brk.js

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ function test(arg) {
2626

2727
test('--debug-brk');
2828
test('--debug-brk=5959');
29+
test('--inspect-brk');
30+
test('--inspect-brk=9230');

0 commit comments

Comments
 (0)