Skip to content

Commit

Permalink
src: make --inspect-brk work with --snapshot-main
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Jun 21, 2021
1 parent 2f67449 commit 28f6bec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/internal/main/mksnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ const mainFile = readFileSync(getOptionValue('--snapshot-main'), 'utf-8');

const snapshotMainFunction = compileSnapshotMain(mainFile);

snapshotMainFunction(requireForUserSnapshot);
if (getOptionValue('--inspect-brk')) {
internalBinding('inspector').callAndPauseOnStart(
snapshotMainFunction, undefined, requireForUserSnapshot);
} else {
snapshotMainFunction(requireForUserSnapshot);
}
12 changes: 10 additions & 2 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "node_v8.h"
#include "node_v8_platform-inl.h"

#if HAVE_INSPECTOR
#include "inspector/worker_inspector.h" // ParentInspectorHandle
#endif

namespace node {

using v8::Context;
Expand Down Expand Up @@ -577,6 +581,10 @@ void SnapshotBuilder::Generate(SnapshotData* out,
nullptr,
node::EnvironmentFlags::kDefaultFlags,
{});

#if HAVE_INSPECTOR
env->InitializeInspector({});
#endif
// Run scripts in lib/internal/bootstrap/
{
TryCatch bootstrapCatch(isolate);
Expand All @@ -602,8 +610,8 @@ void SnapshotBuilder::Generate(SnapshotData* out,
// FIXME(joyee): right now running the loop in the snapshot builder
// seems to intrudoces inconsistencies in JS land that need to be
// synchronized again after snapshot restoration.
// int exit_code = SpinEventLoop(env).FromMaybe(1);
// CHECK_EQ(exit_code, 0);
int exit_code = SpinEventLoop(env).FromMaybe(1);
CHECK_EQ(exit_code, 0);
}

if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
Expand Down

0 comments on commit 28f6bec

Please sign in to comment.