MCPcopy
hub / github.com/microsoft/vscode-js-debug / inspectOrQueue

Function inspectOrQueue

src/targets/node/bootloader.ts:92–187  ·  view source on GitHub ↗
(env: IBootloaderInfo, ownId: string)

Source from the content-addressed store, hash-verified

90}
91
92function inspectOrQueue(env: IBootloaderInfo, ownId: string): boolean {
93 const mode = !isPipeAvailable(env.inspectorIpc)
94 ? Mode.Inactive
95 : env.deferredMode
96 ? Mode.Deferred
97 : Mode.Immediate;
98
99 bootloaderLogger.info(LogTag.Runtime, 'Set debug mode', { mode });
100 if (mode === Mode.Inactive) {
101 return false;
102 }
103
104 // inspector.url() will be defined if --inspect is passed to the process.
105 // Don't call it again to avoid https://github.com/nodejs/node/issues/33012
106 const openedFromCli = inspector.url() !== undefined;
107 if (!openedFromCli) {
108 // if the debugger isn't explicitly enabled, turn it on based on our inspect mode
109 if (!shouldForceProcessIntoDebugMode(env)) {
110 return false;
111 }
112
113 inspector.open(getInspectPort(env), undefined, false); // first call to set the inspector.url()
114 }
115
116 const info: IAutoAttachInfo = {
117 ipcAddress: env.inspectorIpc || '',
118 pid: String(process.pid),
119 telemetry,
120 scriptName: process.argv[1],
121 inspectorURL: inspector.url() as string,
122 waitForDebugger: true,
123 ownId,
124 openerId: env.openerId,
125 };
126
127 if (mode === Mode.Immediate) {
128 spawnWatchdog(env.execPath || process.execPath, info);
129 } else {
130 // The bootloader must call inspector.open() synchronously, which will block
131 // the event loop. Spawn the watchdog handoff in a new process to debug this.
132
133 /*
134 // Minified code is given in spawnSync:
135
136 const c: Socket = require('net').createConnection(process.env.NODE_INSPECTOR_IPC);
137 setTimeout(() => {
138 console.error('timeout');
139 process.exit(1);
140 }, 10000);
141 c.on('error', err => {
142 console.error(err);
143 process.exit(1);
144 });
145 c.on('connect', () => {
146 c.write(process.env.NODE_INSPECTOR_INFO, 'utf-8');
147 c.write(Buffer.from([0]));
148 c.on('data', c => {
149 console.error('read byte', c[0]);

Callers 1

bootloader.tsFile · 0.85

Calls 10

isPipeAvailableFunction · 0.85
getInspectPortFunction · 0.85
spawnWatchdogFunction · 0.85
urlMethod · 0.80
openMethod · 0.80
waitForDebuggerMethod · 0.80
infoMethod · 0.65
errorMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected