Skip to content

Commit 581bddc

Browse files
committed
src: implement runtime option --no-node-snapshot for debugging
PR-URL: #28567 Refs: #28558 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent db55c3c commit 581bddc

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

src/node.cc

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,16 +1052,21 @@ int Start(int argc, char** argv) {
10521052

10531053
{
10541054
Isolate::CreateParams params;
1055-
// TODO(joyeecheung): collect external references and set it in
1056-
// params.external_references.
1057-
std::vector<intptr_t> external_references = {
1058-
reinterpret_cast<intptr_t>(nullptr)};
1059-
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
1060-
const std::vector<size_t>* indexes =
1061-
NodeMainInstance::GetIsolateDataIndexes();
1062-
if (blob != nullptr) {
1063-
params.external_references = external_references.data();
1064-
params.snapshot_blob = blob;
1055+
const std::vector<size_t>* indexes = nullptr;
1056+
std::vector<intptr_t> external_references;
1057+
1058+
bool force_no_snapshot =
1059+
per_process::cli_options->per_isolate->no_node_snapshot;
1060+
if (!force_no_snapshot) {
1061+
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
1062+
if (blob != nullptr) {
1063+
// TODO(joyeecheung): collect external references and set it in
1064+
// params.external_references.
1065+
external_references.push_back(reinterpret_cast<intptr_t>(nullptr));
1066+
params.external_references = external_references.data();
1067+
params.snapshot_blob = blob;
1068+
indexes = NodeMainInstance::GetIsolateDataIndexes();
1069+
}
10651070
}
10661071

10671072
NodeMainInstance main_instance(&params,

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
522522
"track heap object allocations for heap snapshots",
523523
&PerIsolateOptions::track_heap_objects,
524524
kAllowedInEnvironment);
525+
AddOption("--no-node-snapshot",
526+
"", // It's a debug-only option.
527+
&PerIsolateOptions::no_node_snapshot,
528+
kAllowedInEnvironment);
525529

526530
// Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS.
527531
AddOption("--abort-on-uncaught-exception",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class PerIsolateOptions : public Options {
171171
public:
172172
std::shared_ptr<EnvironmentOptions> per_env { new EnvironmentOptions() };
173173
bool track_heap_objects = false;
174+
bool no_node_snapshot = false;
174175

175176
#ifdef NODE_REPORT
176177
bool report_uncaught_exception = false;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
// Flags: --no-node-snapshot
4+
5+
require('../common');

test/parallel/test-process-env-allowed-flags-are-documented.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ const undocumented = difference(process.allowedNodeEnvironmentFlags,
7979
// Remove intentionally undocumented options.
8080
assert(undocumented.delete('--debug-arraybuffer-allocations'));
8181
assert(undocumented.delete('--experimental-worker'));
82+
assert(undocumented.delete('--no-node-snapshot'));
83+
8284
assert.strictEqual(undocumented.size, 0,
8385
'The following options are not documented as allowed in ' +
8486
`NODE_OPTIONS in ${cliMd}: ${[...undocumented].join(' ')}`);

0 commit comments

Comments
 (0)