Skip to content

Commit 6cb314b

Browse files
joyeecheunglegendecas
authored andcommitted
bootstrap: print information for snapshot at environment exit in debug
Print information relevant to snapshot building at the environment exit when NODE_DEBUG_NATIVE is set to include mksnapshot. This helps us understand what need to be fixed to build a snapshot when a script is run to completion. PR-URL: #37967 Refs: #37476 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9cfb418 commit 6cb314b

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/api/embed_helpers.cc

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Maybe<int> SpinEventLoop(Environment* env) {
5353
if (env->is_stopping()) return Nothing<int>();
5454

5555
env->set_trace_sync_io(false);
56+
env->PrintInfoForSnapshotIfDebug();
5657
env->VerifyNoStrongBaseObjects();
5758
return EmitProcessExit(env);
5859
}

src/env.cc

+19
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,25 @@ void Environment::RemoveUnmanagedFd(int fd) {
12321232
}
12331233
}
12341234

1235+
void Environment::PrintInfoForSnapshotIfDebug() {
1236+
if (enabled_debug_list()->enabled(DebugCategory::MKSNAPSHOT)) {
1237+
fprintf(stderr, "BaseObjects at the exit of the Environment:\n");
1238+
PrintAllBaseObjects();
1239+
fprintf(stderr, "\nNative modules without cache:\n");
1240+
for (const auto& s : native_modules_without_cache) {
1241+
fprintf(stderr, "%s\n", s.c_str());
1242+
}
1243+
fprintf(stderr, "\nNative modules with cache:\n");
1244+
for (const auto& s : native_modules_with_cache) {
1245+
fprintf(stderr, "%s\n", s.c_str());
1246+
}
1247+
fprintf(stderr, "\nStatic bindings (need to be registered):\n");
1248+
for (const auto mod : internal_bindings) {
1249+
fprintf(stderr, "%s:%s\n", mod->nm_filename, mod->nm_modname);
1250+
}
1251+
}
1252+
}
1253+
12351254
void Environment::PrintAllBaseObjects() {
12361255
size_t i = 0;
12371256
std::cout << "BaseObjects\n";

src/env.h

+2
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ class Environment : public MemoryRetainer {
960960
void CreateProperties();
961961
void DeserializeProperties(const EnvSerializeInfo* info);
962962

963+
void PrintInfoForSnapshotIfDebug();
963964
void PrintAllBaseObjects();
964965
void VerifyNoStrongBaseObjects();
965966
void EnqueueDeserializeRequest(DeserializeRequestCallback cb,
@@ -1123,6 +1124,7 @@ class Environment : public MemoryRetainer {
11231124
// List of id's that have been destroyed and need the destroy() cb called.
11241125
inline std::vector<double>* destroy_async_id_list();
11251126

1127+
std::set<struct node_module*> internal_bindings;
11261128
std::set<std::string> native_modules_with_cache;
11271129
std::set<std::string> native_modules_without_cache;
11281130
// This is only filled during deserialization. We use a vector since

src/node_binding.cc

+1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
582582
node_module* mod = FindModule(modlist_internal, *module_v, NM_F_INTERNAL);
583583
if (mod != nullptr) {
584584
exports = InitModule(env, mod, module);
585+
env->internal_bindings.insert(mod);
585586
} else if (!strcmp(*module_v, "constants")) {
586587
exports = Object::New(env->isolate());
587588
CHECK(

0 commit comments

Comments
 (0)