Skip to content

Commit 9ca41e9

Browse files
committed
src: introduce inspect-brk-node
This commit is a suggestion to add a new option to the node executable to allow for breaking in node's javascript bootstrapper code. Previously I've been able to set breakpoints in node bootstrapper code and then restart the debugging session and those breakpoints would be hit, but I don't seem to be able to do so anymore. Having this option would allow me to use this option and then step through or add more break points as needed. PR-URL: #20819 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2f1a23e commit 9ca41e9

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

lib/internal/bootstrap/loaders.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@
4040
'use strict';
4141

4242
(function bootstrapInternalLoaders(process, getBinding, getLinkedBinding,
43-
getInternalBinding) {
43+
getInternalBinding, debugBreak) {
44+
if (debugBreak)
45+
debugger; // eslint-disable-line no-debugger
46+
4447
const {
4548
apply: ReflectApply,
4649
deleteProperty: ReflectDeleteProperty,

src/node.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,11 @@ void SetupProcessObject(Environment* env,
21902190
"_breakFirstLine", True(env->isolate()));
21912191
}
21922192

2193+
if (debug_options.break_node_first_line()) {
2194+
READONLY_DONT_ENUM_PROPERTY(process,
2195+
"_breakNodeFirstLine", True(env->isolate()));
2196+
}
2197+
21932198
// --inspect --debug-brk
21942199
if (debug_options.deprecated_invocation()) {
21952200
READONLY_DONT_ENUM_PROPERTY(process,
@@ -2401,7 +2406,8 @@ void LoadEnvironment(Environment* env) {
24012406
env->process_object(),
24022407
get_binding_fn,
24032408
get_linked_binding_fn,
2404-
get_internal_binding_fn
2409+
get_internal_binding_fn,
2410+
Boolean::New(env->isolate(), debug_options.break_node_first_line())
24052411
};
24062412

24072413
// Bootstrap internal loaders

src/node_debug_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ DebugOptions::DebugOptions() :
5858
inspector_enabled_(false),
5959
deprecated_debug_(false),
6060
break_first_line_(false),
61+
break_node_first_line_(false),
6162
host_name_("127.0.0.1"), port_(-1) { }
6263

6364
bool DebugOptions::ParseOption(const char* argv0, const std::string& option) {
@@ -90,6 +91,9 @@ bool DebugOptions::ParseOption(const char* argv0, const std::string& option) {
9091
} else if (option_name == "--inspect-brk") {
9192
inspector_enabled_ = true;
9293
break_first_line_ = true;
94+
} else if (option_name == "--inspect-brk-node") {
95+
inspector_enabled_ = true;
96+
break_node_first_line_ = true;
9397
} else if (option_name == "--debug-brk") {
9498
break_first_line_ = true;
9599
deprecated_debug_ = true;

src/node_debug_options.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ class DebugOptions {
1919
bool invalid_invocation() const {
2020
return deprecated_debug_ && !inspector_enabled_;
2121
}
22-
bool wait_for_connect() const { return break_first_line_; }
22+
bool wait_for_connect() const {
23+
return break_first_line_ || break_node_first_line_;
24+
}
2325
std::string host_name() const { return host_name_; }
2426
void set_host_name(std::string host_name) { host_name_ = host_name; }
2527
int port() const;
2628
void set_port(int port) { port_ = port; }
29+
bool break_node_first_line() const { return break_node_first_line_; }
2730

2831
private:
2932
bool inspector_enabled_;
3033
bool deprecated_debug_;
3134
bool break_first_line_;
35+
bool break_node_first_line_;
3236
std::string host_name_;
3337
int port_;
3438
};

0 commit comments

Comments
 (0)