Skip to content

Commit 1b45704

Browse files
joyeecheungtargos
authored andcommitted
inspector: patch C++ debug options instead of process._breakFirstLine
Instead of patching process._breakFirstLine to inform the JS land to wait for the debugger, check that the JS land has not yet serialized the options and then patch the debug options from C++. The changes will be carried into JS later during option serialization. PR-URL: #26602 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 5e64acd commit 1b45704

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

src/env-inl.h

+8
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ inline void Environment::set_has_run_bootstrapping_code(bool value) {
684684
has_run_bootstrapping_code_ = value;
685685
}
686686

687+
inline bool Environment::has_serialized_options() const {
688+
return has_serialized_options_;
689+
}
690+
691+
inline void Environment::set_has_serialized_options(bool value) {
692+
has_serialized_options_ = value;
693+
}
694+
687695
inline bool Environment::is_main_thread() const {
688696
return flags_ & kIsMainThread;
689697
}

src/env.h

+5
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,9 @@ class Environment {
887887
inline bool has_run_bootstrapping_code() const;
888888
inline void set_has_run_bootstrapping_code(bool has_run_bootstrapping_code);
889889

890+
inline bool has_serialized_options() const;
891+
inline void set_has_serialized_options(bool has_serialized_options);
892+
890893
static uint64_t AllocateThreadId();
891894
static constexpr uint64_t kNoThreadId = -1;
892895

@@ -1104,6 +1107,8 @@ class Environment {
11041107
std::unordered_map<std::string, uint64_t> performance_marks_;
11051108

11061109
bool has_run_bootstrapping_code_ = false;
1110+
bool has_serialized_options_ = false;
1111+
11071112
bool can_call_into_js_ = true;
11081113
Flags flags_;
11091114
uint64_t thread_id_;

src/inspector_agent.cc

+5-11
Original file line numberDiff line numberDiff line change
@@ -728,18 +728,12 @@ bool Agent::Start(const std::string& path,
728728
return false;
729729
}
730730

731-
// TODO(joyeecheung): we should not be using process as a global object
732-
// to transport --inspect-brk. Instead, the JS land can get this through
733-
// require('internal/options') since it should be set once CLI parsing
734-
// is done.
731+
// Patch the debug options to implement waitForDebuggerOnStart for
732+
// the NodeWorker.enable method.
735733
if (wait_for_connect) {
736-
HandleScope scope(parent_env_->isolate());
737-
parent_env_->process_object()->DefineOwnProperty(
738-
parent_env_->context(),
739-
FIXED_ONE_BYTE_STRING(parent_env_->isolate(), "_breakFirstLine"),
740-
True(parent_env_->isolate()),
741-
static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum))
742-
.FromJust();
734+
CHECK(!parent_env_->has_serialized_options());
735+
debug_options_.EnableBreakFirstLine();
736+
parent_env_->options()->get_debug_options()->EnableBreakFirstLine();
743737
client_->waitForFrontend();
744738
}
745739
return true;

src/node_options.cc

+1
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) {
553553
return env->ThrowError(
554554
"Should not query options before bootstrapping is done");
555555
}
556+
env->set_has_serialized_options(true);
556557

557558
Isolate* isolate = env->isolate();
558559
Local<Context> context = env->context();

src/node_options.h

+6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class DebugOptions : public Options {
8585
return deprecated_debug && !inspector_enabled;
8686
}
8787

88+
// Used to patch the options as if --inspect-brk is passed.
89+
void EnableBreakFirstLine() {
90+
inspector_enabled = true;
91+
break_first_line = true;
92+
}
93+
8894
bool wait_for_connect() const {
8995
return break_first_line || break_node_first_line;
9096
}

0 commit comments

Comments
 (0)