src: implement runtime option --no-node-snapshot for debugging

PR-URL: https://github.com/nodejs/node/pull/28567
Refs: https://github.com/nodejs/node/issues/28558
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Joyee Cheung 2019-07-06 02:43:27 +08:00
parent db55c3cfc1
commit 581bddc656
No known key found for this signature in database
GPG Key ID: 92B78A53C8303B8D
5 changed files with 27 additions and 10 deletions

View File

@ -1052,16 +1052,21 @@ int Start(int argc, char** argv) {
{
Isolate::CreateParams params;
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.
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) {
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,

View File

@ -522,6 +522,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",

View File

@ -171,6 +171,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;

View File

@ -0,0 +1,5 @@
'use strict';
// Flags: --no-node-snapshot
require('../common');

View File

@ -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(' ')}`);