Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ an additional module during the snapshot building process is needed,
please file a request in the [Node.js issue tracker][] and link to it in the
[tracking issue for user-land snapshots][].

During snapshot building, a debugger cannot be attached to the process.
`--build-snapshot` cannot be used together with `--inspect`, `--inspect-brk` or
`--inspect-wait`.

### `--build-snapshot-config`

<!-- YAML
Expand Down
12 changes: 11 additions & 1 deletion src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,11 @@ class NodeInspectorClient : public V8InspectorClient {
is_main_ ? GetHumanReadableProcessName() : GetWorkerLabel(env);
ContextInfo info(name);
info.is_default = true;
contextCreated(env->context(), info);
// V8 does not allow a debugger to be attached while a startup or
// a debug context ID to be set during snapshot building.
if (!env->isolate_data()->is_building_snapshot()) {
contextCreated(env->context(), info);
}
}

void runMessageLoopOnPause(int context_group_id) override {
Expand Down Expand Up @@ -923,6 +927,12 @@ bool Agent::StartIoThread() {

CHECK_NOT_NULL(client_);

if (parent_env_->isolate_data()->is_building_snapshot()) {
fprintf(stderr,
"The inspector cannot be activated while building a snapshot.\n");
return false;
}

io_ = InspectorIo::Start(client_->getThreadHandle(),
path_,
host_port_,
Expand Down
38 changes: 21 additions & 17 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,16 @@ void PerProcessOptions::CheckProcessTimeoutOptions(
// make the timeout fire while the debugger is in control, so the two cannot
// be combined. Runtime activation of the inspector is rejected separately.
const DebugOptions& debug_options = per_isolate->per_env->debug_options();
const char* debug_option = nullptr;
if (debug_options.break_node_first_line) {
debug_option = "--inspect-brk-node";
} else if (debug_options.break_first_line) {
debug_option = "--inspect-brk";
} else if (debug_options.inspect_wait) {
debug_option = "--inspect-wait";
} else if (debug_options.inspector_enabled) {
debug_option = "--inspect";
} else if (debug_options.host_port.host() != "127.0.0.1" ||
debug_options.host_port.port() !=
DebugOptions::kDefaultInspectorPort) {
// We can't catch the case where the value passed is the default value,
// then the option just becomes a noop which is fine.
debug_option = "--inspect-port";
} else if (debug_options.inspect_publish_uid_string != "stderr,http") {
debug_option = "--inspect-publish-uid";
const char* debug_option = debug_options.inspector_option_name();
if (debug_option == nullptr) {
if (debug_options.host_port.host() != "127.0.0.1" ||
debug_options.host_port.port() != DebugOptions::kDefaultInspectorPort) {
// We can't catch the case where the value passed is the default value,
// then the option just becomes a noop which is fine.
debug_option = "--inspect-port";
} else if (debug_options.inspect_publish_uid_string != "stderr,http") {
debug_option = "--inspect-publish-uid";
}
}
if (debug_option != nullptr) {
errors->push_back(std::string("either --process-timeout or ") +
Expand Down Expand Up @@ -297,6 +290,17 @@ void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors,
HandleMaxOldSpaceSizePercentage(errors, &max_old_space_size_percentage);
}

if (build_snapshot) {
// V8 does not allow a debugger to be attached during snapshot building.
const char* debug_option =
per_env->debug_options().inspector_option_name();
if (debug_option != nullptr) {
errors->push_back(
std::string("--build-snapshot cannot be used together with ") +
debug_option);
}
}

per_env->CheckOptions(errors, argv);
}

Expand Down
8 changes: 8 additions & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ class DebugOptions : public Options {
return break_first_line || break_node_first_line;
}

const char* inspector_option_name() const {
if (break_node_first_line) return "--inspect-brk-node";
if (break_first_line) return "--inspect-brk";
if (inspect_wait) return "--inspect-wait";
if (inspector_enabled) return "--inspect";
return nullptr;
}

void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) override;
};
Expand Down
11 changes: 8 additions & 3 deletions test/parallel/test-inspect-address-in-use.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@

tmpdir.refresh();

testChildProcess(
(port) => [`--inspect=${port}`, '--build-snapshot', entry], 0,
{ cwd: tmpdir.path });
// V8 does not allow a debugger to be attached during snapshot building.
spawnSyncAndExit(process.execPath, ['--inspect=0', '--build-snapshot', entry],
{ cwd: tmpdir.path },

Check failure on line 47 in test/parallel/test-inspect-address-in-use.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 17 spaces but found 2
{

Check failure on line 48 in test/parallel/test-inspect-address-in-use.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 17 spaces but found 2
status: 9,

Check failure on line 49 in test/parallel/test-inspect-address-in-use.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 19 spaces but found 4
signal: null,

Check failure on line 50 in test/parallel/test-inspect-address-in-use.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 19 spaces but found 4
stderr: /--build-snapshot cannot be used together with --inspect/,

Check failure on line 51 in test/parallel/test-inspect-address-in-use.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 19 spaces but found 4
});

Check failure on line 52 in test/parallel/test-inspect-address-in-use.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 17 spaces but found 2

testChildProcess(
(port) => [`--inspect=${port}`, entry], 0);
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-snapshot-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const entry = fixtures.path('snapshot', 'console.js');
console.log(child.stderr.toString());
assert.strictEqual(child.status, 0);
}
assert.deepStrictEqual(Object.keys(console), JSON.parse(stdout));
// console.createTask is not available during snapshot buildling.
assert.deepStrictEqual(
Object.keys(console).filter((key) => key !== 'createTask'),
JSON.parse(stdout));
const stats = fs.statSync(tmpdir.resolve('snapshot.blob'));
assert(stats.isFile());
}
Expand Down
Loading