Skip to content

Commit

Permalink
src: implement runtime option --no-node-snapshot for debugging
Browse files Browse the repository at this point in the history
PR-URL: #28567
Refs: #28558
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Jul 20, 2019
1 parent 0e2cbe6 commit 4f035e4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1004,16 +1004,21 @@ int Start(int argc, char** argv) {

{
Isolate::CreateParams params;
// TODO(joyeecheung): collect external references and set it in
// params.external_references.
std::vector<intptr_t> external_references = {
reinterpret_cast<intptr_t>(nullptr)};
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
const std::vector<size_t>* indexes =
NodeMainInstance::GetIsolateDataIndexes();
if (blob != nullptr) {
params.external_references = external_references.data();
params.snapshot_blob = blob;
const std::vector<size_t>* indexes = nullptr;
std::vector<intptr_t> external_references;

bool force_no_snapshot =
per_process::cli_options->per_isolate->no_node_snapshot;
if (!force_no_snapshot) {
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
if (blob != nullptr) {
// TODO(joyeecheung): collect external references and set it in
// params.external_references.
external_references.push_back(reinterpret_cast<intptr_t>(nullptr));
params.external_references = external_references.data();
params.snapshot_blob = blob;
indexes = NodeMainInstance::GetIsolateDataIndexes();
}
}

NodeMainInstance main_instance(&params,
Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
"track heap object allocations for heap snapshots",
&PerIsolateOptions::track_heap_objects,
kAllowedInEnvironment);
AddOption("--no-node-snapshot",
"", // It's a debug-only option.
&PerIsolateOptions::no_node_snapshot,
kAllowedInEnvironment);

// Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS.
AddOption("--abort-on-uncaught-exception",
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class PerIsolateOptions : public Options {
public:
std::shared_ptr<EnvironmentOptions> per_env { new EnvironmentOptions() };
bool track_heap_objects = false;
bool no_node_snapshot = false;

#ifdef NODE_REPORT
bool report_uncaught_exception = false;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-no-node-snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

// Flags: --no-node-snapshot

require('../common');
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const undocumented = difference(process.allowedNodeEnvironmentFlags,
// Remove intentionally undocumented options.
assert(undocumented.delete('--debug-arraybuffer-allocations'));
assert(undocumented.delete('--experimental-worker'));
assert(undocumented.delete('--no-node-snapshot'));

assert.strictEqual(undocumented.size, 0,
'The following options are not documented as allowed in ' +
`NODE_OPTIONS in ${cliMd}: ${[...undocumented].join(' ')}`);

0 comments on commit 4f035e4

Please sign in to comment.