Skip to content

Commit 28f6bec

Browse files
committed
src: make --inspect-brk work with --snapshot-main
1 parent 2f67449 commit 28f6bec

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/internal/main/mksnapshot.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,9 @@ const mainFile = readFileSync(getOptionValue('--snapshot-main'), 'utf-8');
107107

108108
const snapshotMainFunction = compileSnapshotMain(mainFile);
109109

110-
snapshotMainFunction(requireForUserSnapshot);
110+
if (getOptionValue('--inspect-brk')) {
111+
internalBinding('inspector').callAndPauseOnStart(
112+
snapshotMainFunction, undefined, requireForUserSnapshot);
113+
} else {
114+
snapshotMainFunction(requireForUserSnapshot);
115+
}

src/node_snapshotable.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include "node_v8.h"
1414
#include "node_v8_platform-inl.h"
1515

16+
#if HAVE_INSPECTOR
17+
#include "inspector/worker_inspector.h" // ParentInspectorHandle
18+
#endif
19+
1620
namespace node {
1721

1822
using v8::Context;
@@ -577,6 +581,10 @@ void SnapshotBuilder::Generate(SnapshotData* out,
577581
nullptr,
578582
node::EnvironmentFlags::kDefaultFlags,
579583
{});
584+
585+
#if HAVE_INSPECTOR
586+
env->InitializeInspector({});
587+
#endif
580588
// Run scripts in lib/internal/bootstrap/
581589
{
582590
TryCatch bootstrapCatch(isolate);
@@ -602,8 +610,8 @@ void SnapshotBuilder::Generate(SnapshotData* out,
602610
// FIXME(joyee): right now running the loop in the snapshot builder
603611
// seems to intrudoces inconsistencies in JS land that need to be
604612
// synchronized again after snapshot restoration.
605-
// int exit_code = SpinEventLoop(env).FromMaybe(1);
606-
// CHECK_EQ(exit_code, 0);
613+
int exit_code = SpinEventLoop(env).FromMaybe(1);
614+
CHECK_EQ(exit_code, 0);
607615
}
608616

609617
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {

0 commit comments

Comments
 (0)