GeezerVison is showing github.com — src: do not enable the inspector during snapshot building · nodejs/node@00839e2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -669,6 +669,10 @@ an additional module during the snapshot building process is needed, | 669 | 669 | please file a request in the [Node.js issue tracker][] and link to it in the | 670 | 670 | [tracking issue for user-land snapshots][]. | 671 | 671 |
| | 672 | +During snapshot building, a debugger cannot be attached to the process. | | 673 | +`--build-snapshot` cannot be used together with `--inspect`, `--inspect-brk` or | | 674 | +`--inspect-wait`. | | 675 | + | 672 | 676 | ### `--build-snapshot-config` | 673 | 677 |
| 674 | 678 | <!-- YAML | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -407,6 +407,9 @@ runtime, using either \fBv8.startupSnapshot.setDeserializeMainFunction()\fR or | 407 | 407 | an additional module during the snapshot building process is needed, | 408 | 408 | please file a request in the Node.js issue tracker and link to it in the | 409 | 409 | tracking issue for user-land snapshots. | | 410 | +During snapshot building, a debugger cannot be attached to the process. | | 411 | +\fB--build-snapshot\fR cannot be used together with \fB--inspect\fR, \fB--inspect-brk\fR or | | 412 | +\fB--inspect-wait\fR. | 410 | 413 | . | 411 | 414 | .It Fl -build-snapshot-config | 412 | 415 | Specifies the path to a JSON configuration file which configures snapshot | |
Collapse file Copy file name to clipboardExpand all lines: src/inspector_agent.cc +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -528,7 +528,11 @@ class NodeInspectorClient : public V8InspectorClient { | 528 | 528 | is_main_ ? GetHumanReadableProcessName() : GetWorkerLabel(env); | 529 | 529 | ContextInfo info(name); | 530 | 530 | info.is_default = true; | 531 | | - contextCreated(env->context(), info); | | 531 | + // V8 does not allow a debugger to be attached while a startup or | | 532 | + // a debug context ID to be set during snapshot building. | | 533 | + if (!env->isolate_data()->is_building_snapshot()) { | | 534 | + contextCreated(env->context(), info); | | 535 | + } | 532 | 536 | } | 533 | 537 |
| 534 | 538 | void runMessageLoopOnPause(int context_group_id) override { | @@ -923,6 +927,12 @@ bool Agent::StartIoThread() { | 923 | 927 |
| 924 | 928 | CHECK_NOT_NULL(client_); | 925 | 929 |
| | 930 | + if (parent_env_->isolate_data()->is_building_snapshot()) { | | 931 | + fprintf(stderr, | | 932 | + "The inspector cannot be activated while building a snapshot.\n"); | | 933 | + return false; | | 934 | + } | | 935 | + | 926 | 936 | io_ = InspectorIo::Start(client_->getThreadHandle(), | 927 | 937 | path_, | 928 | 938 | host_port_, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +20-17Lines changed: 20 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -202,23 +202,16 @@ void PerProcessOptions::CheckProcessTimeoutOptions( | 202 | 202 | // make the timeout fire while the debugger is in control, so the two cannot | 203 | 203 | // be combined. Runtime activation of the inspector is rejected separately. | 204 | 204 | const DebugOptions& debug_options = per_isolate->per_env->debug_options(); | 205 | | - const char* debug_option = nullptr; | 206 | | - if (debug_options.break_node_first_line) { | 207 | | - debug_option = "--inspect-brk-node"; | 208 | | - } else if (debug_options.break_first_line) { | 209 | | - debug_option = "--inspect-brk"; | 210 | | - } else if (debug_options.inspect_wait) { | 211 | | - debug_option = "--inspect-wait"; | 212 | | - } else if (debug_options.inspector_enabled) { | 213 | | - debug_option = "--inspect"; | 214 | | - } else if (debug_options.host_port.host() != "127.0.0.1" || | 215 | | - debug_options.host_port.port() != | 216 | | - DebugOptions::kDefaultInspectorPort) { | 217 | | - // We can't catch the case where the value passed is the default value, | 218 | | - // then the option just becomes a noop which is fine. | 219 | | - debug_option = "--inspect-port"; | 220 | | - } else if (debug_options.inspect_publish_uid_string != "stderr,http") { | 221 | | - debug_option = "--inspect-publish-uid"; | | 205 | + const char* debug_option = debug_options.inspector_option_name(); | | 206 | + if (debug_option == nullptr) { | | 207 | + if (debug_options.host_port.host() != "127.0.0.1" || | | 208 | + debug_options.host_port.port() != DebugOptions::kDefaultInspectorPort) { | | 209 | + // We can't catch the case where the value passed is the default value, | | 210 | + // then the option just becomes a noop which is fine. | | 211 | + debug_option = "--inspect-port"; | | 212 | + } else if (debug_options.inspect_publish_uid_string != "stderr,http") { | | 213 | + debug_option = "--inspect-publish-uid"; | | 214 | + } | 222 | 215 | } | 223 | 216 | if (debug_option != nullptr) { | 224 | 217 | errors->push_back(std::string("either --process-timeout or ") + | @@ -296,6 +289,16 @@ void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors, | 296 | 289 | HandleMaxOldSpaceSizePercentage(errors, &max_old_space_size_percentage); | 297 | 290 | } | 298 | 291 |
| | 292 | + if (build_snapshot) { | | 293 | + // V8 does not allow a debugger to be attached during snapshot building. | | 294 | + const char* debug_option = per_env->debug_options().inspector_option_name(); | | 295 | + if (debug_option != nullptr) { | | 296 | + errors->push_back( | | 297 | + std::string("--build-snapshot cannot be used together with ") + | | 298 | + debug_option); | | 299 | + } | | 300 | + } | | 301 | + | 299 | 302 | per_env->CheckOptions(errors, argv); | 300 | 303 | } | 301 | 304 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,14 @@ class DebugOptions : public Options { | 112 | 112 | return break_first_line || break_node_first_line; | 113 | 113 | } | 114 | 114 |
| | 115 | + const char* inspector_option_name() const { | | 116 | + if (break_node_first_line) return "--inspect-brk-node"; | | 117 | + if (break_first_line) return "--inspect-brk"; | | 118 | + if (inspect_wait) return "--inspect-wait"; | | 119 | + if (inspector_enabled) return "--inspect"; | | 120 | + return nullptr; | | 121 | + } | | 122 | + | 115 | 123 | void CheckOptions(std::vector<std::string>* errors, | 116 | 124 | std::vector<std::string>* argv) override; | 117 | 125 | }; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-inspect-address-in-use.js +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,9 +42,14 @@ function testChildProcess(getArgs, exitCode, options) { | 42 | 42 |
| 43 | 43 | tmpdir.refresh(); | 44 | 44 |
| 45 | | -testChildProcess( | 46 | | - (port) => [`--inspect=${port}`, '--build-snapshot', entry], 0, | 47 | | - { cwd: tmpdir.path }); | | 45 | +// V8 does not allow a debugger to be attached during snapshot building. | | 46 | +spawnSyncAndExit(process.execPath, ['--inspect=0', '--build-snapshot', entry], | | 47 | + { cwd: tmpdir.path }, | | 48 | + { | | 49 | + status: 9, | | 50 | + signal: null, | | 51 | + stderr: /--build-snapshot cannot be used together with --inspect/, | | 52 | + }); | 48 | 53 |
| 49 | 54 | testChildProcess( | 50 | 55 | (port) => [`--inspect=${port}`, entry], 0); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-snapshot-console.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,7 +30,10 @@ const entry = fixtures.path('snapshot', 'console.js'); | 30 | 30 | console.log(child.stderr.toString()); | 31 | 31 | assert.strictEqual(child.status, 0); | 32 | 32 | } | 33 | | - assert.deepStrictEqual(Object.keys(console), JSON.parse(stdout)); | | 33 | + // console.createTask is not available during snapshot buildling. | | 34 | + assert.deepStrictEqual( | | 35 | + Object.keys(console).filter((key) => key !== 'createTask'), | | 36 | + JSON.parse(stdout)); | 34 | 37 | const stats = fs.statSync(tmpdir.resolve('snapshot.blob')); | 35 | 38 | assert(stats.isFile()); | 36 | 39 | } | |
|