Skip to content

Commit

Permalink
src: introduce inspect-brk-node
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
danbev authored and targos committed Jun 22, 2018
1 parent a1580a0 commit 75e07fe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
'use strict';

(function bootstrapInternalLoaders(process, getBinding, getLinkedBinding,
getInternalBinding) {
getInternalBinding, debugBreak) {
if (debugBreak)
debugger; // eslint-disable-line no-debugger

const {
apply: ReflectApply,
deleteProperty: ReflectDeleteProperty,
Expand Down
8 changes: 7 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,11 @@ void SetupProcessObject(Environment* env,
"_breakFirstLine", True(env->isolate()));
}

if (debug_options.break_node_first_line()) {
READONLY_DONT_ENUM_PROPERTY(process,
"_breakNodeFirstLine", True(env->isolate()));
}

// --inspect --debug-brk
if (debug_options.deprecated_invocation()) {
READONLY_DONT_ENUM_PROPERTY(process,
Expand Down Expand Up @@ -2950,7 +2955,8 @@ void LoadEnvironment(Environment* env) {
env->process_object(),
get_binding_fn,
get_linked_binding_fn,
get_internal_binding_fn
get_internal_binding_fn,
Boolean::New(env->isolate(), debug_options.break_node_first_line())
};

// Bootstrap internal loaders
Expand Down
4 changes: 4 additions & 0 deletions src/node_debug_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ DebugOptions::DebugOptions() :
inspector_enabled_(false),
deprecated_debug_(false),
break_first_line_(false),
break_node_first_line_(false),
host_name_("127.0.0.1"), port_(-1) { }

bool DebugOptions::ParseOption(const char* argv0, const std::string& option) {
Expand Down Expand Up @@ -90,6 +91,9 @@ bool DebugOptions::ParseOption(const char* argv0, const std::string& option) {
} else if (option_name == "--inspect-brk") {
inspector_enabled_ = true;
break_first_line_ = true;
} else if (option_name == "--inspect-brk-node") {
inspector_enabled_ = true;
break_node_first_line_ = true;
} else if (option_name == "--debug-brk") {
break_first_line_ = true;
deprecated_debug_ = true;
Expand Down
6 changes: 5 additions & 1 deletion src/node_debug_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ class DebugOptions {
bool invalid_invocation() const {
return deprecated_debug_ && !inspector_enabled_;
}
bool wait_for_connect() const { return break_first_line_; }
bool wait_for_connect() const {
return break_first_line_ || break_node_first_line_;
}
std::string host_name() const { return host_name_; }
void set_host_name(std::string host_name) { host_name_ = host_name; }
int port() const;
void set_port(int port) { port_ = port; }
bool break_node_first_line() const { return break_node_first_line_; }

private:
bool inspector_enabled_;
bool deprecated_debug_;
bool break_first_line_;
bool break_node_first_line_;
std::string host_name_;
int port_;
};
Expand Down

0 comments on commit 75e07fe

Please sign in to comment.