From a2a1d0a55e2f15088097e37b6d21775bd6aaaf70 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 18 May 2018 12:51:20 +0200 Subject: [PATCH 1/2] 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. $ ./node --help Usage: node [options] [ -e script | script.js | - ] [arguments] node inspect script.js [arguments] Options: ... --inspect-brk-node will break in node's bootstrap code (default: false) ... Currently test are missing as I wanted to see if this is worth pursuing first. --- lib/internal/bootstrap/loaders.js | 5 ++++- src/node.cc | 10 +++++++++- src/node_debug_options.cc | 4 ++++ src/node_debug_options.h | 6 +++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 4291092532ec94..de911eb841e7ed 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -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, diff --git a/src/node.cc b/src/node.cc index 2088f505d8c328..da0400848c542f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -2843,6 +2843,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, @@ -3077,7 +3082,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 @@ -3147,6 +3153,8 @@ static void PrintHelp() { " --inspect-brk[=[host:]port]\n" " activate inspector on host:port\n" " and break at start of user script\n" + " --inspect-brk-node will break in node's bootstrap code\n" + " (default: false)\n" " --inspect-port=[host:]port\n" " set host:port for inspector\n" " --inspect[=[host:]port] activate inspector on host:port\n" diff --git a/src/node_debug_options.cc b/src/node_debug_options.cc index 3ec773132047de..5fc29059ddc84f 100644 --- a/src/node_debug_options.cc +++ b/src/node_debug_options.cc @@ -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) { @@ -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; diff --git a/src/node_debug_options.h b/src/node_debug_options.h index 99364f40989f6a..98922ab099ac77 100644 --- a/src/node_debug_options.h +++ b/src/node_debug_options.h @@ -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_; }; From f3675917850660e492cfb639c0c67314ad41aa2d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 7 Jun 2018 13:22:06 +0200 Subject: [PATCH 2/2] squash: remove --inspect-brk-node help message --- src/node.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/node.cc b/src/node.cc index da0400848c542f..f09ce6779b8c0f 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3153,8 +3153,6 @@ static void PrintHelp() { " --inspect-brk[=[host:]port]\n" " activate inspector on host:port\n" " and break at start of user script\n" - " --inspect-brk-node will break in node's bootstrap code\n" - " (default: false)\n" " --inspect-port=[host:]port\n" " set host:port for inspector\n" " --inspect[=[host:]port] activate inspector on host:port\n"