Skip to content

Commit 75e07fe

Browse files
danbevtargos
authored andcommitted
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 a1580a0 commit 75e07fe

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
@@ -2716,6 +2716,11 @@ void SetupProcessObject(Environment* env,
27162716
"_breakFirstLine", True(env->isolate()));
27172717
}
27182718

2719+
if (debug_options.break_node_first_line()) {
2720+
READONLY_DONT_ENUM_PROPERTY(process,
2721+
"_breakNodeFirstLine", True(env->isolate()));
2722+
}
2723+
27192724
// --inspect --debug-brk
27202725
if (debug_options.deprecated_invocation()) {
27212726
READONLY_DONT_ENUM_PROPERTY(process,
@@ -2950,7 +2955,8 @@ void LoadEnvironment(Environment* env) {
29502955
env->process_object(),
29512956
get_binding_fn,
29522957
get_linked_binding_fn,
2953-
get_internal_binding_fn
2958+
get_internal_binding_fn,
2959+
Boolean::New(env->isolate(), debug_options.break_node_first_line())
29542960
};
29552961

29562962
// 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)