================ @@ -115,41 +123,71 @@ export class LLDBDapDescriptorFactory } const configEnvironment = config.get<{ [key: string]: string }>("environment") || {}; - const dapPath = await getDAPExecutable(session); + const dapPath = (await getDAPExecutable(session)) ?? executable?.command; + + if (!dapPath) { + LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(); + return undefined; + } + + if (!(await isExecutable(dapPath))) { + LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath); + return; + } + const dbgOptions = { env: { ...executable?.options?.env, ...configEnvironment, ...env, }, }; - if (dapPath) { - if (!(await isExecutable(dapPath))) { - LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath); - return undefined; - } - return new vscode.DebugAdapterExecutable(dapPath, [], dbgOptions); - } else if (executable) { - if (!(await isExecutable(executable.command))) { - LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(executable.command); - return undefined; - } - return new vscode.DebugAdapterExecutable( - executable.command, - executable.args, - dbgOptions, - ); + const dbgArgs = executable?.args ?? []; + + const serverMode = config.get<boolean>('serverMode', false); + if (serverMode) { + const { host, port } = await this.startServer(dapPath, dbgArgs, dbgOptions); + return new vscode.DebugAdapterServer(port, host); } - return undefined; + + return new vscode.DebugAdapterExecutable(dapPath, dbgArgs, dbgOptions); + } + + startServer(dapPath: string, args: string[], options: child_process.CommonSpawnOptions): Promise<{ host: string, port: number }> { + if (this.server) return this.server; + + this.server = new Promise(resolve => { + args.push( + '--connection', + 'connect://localhost:0' + ); + const server = child_process.spawn(dapPath, args, options); + server.stdout!.setEncoding('utf8').once('data', (data: string) => { ---------------- vogelsgesang wrote:
Is this actually "race-free" (for lack of a better term)? Looking at https://nodejs.org/api/stream.html#event-data I am not sure if we have a guarantee that the complete stdout content will be delivered in a single `data` event or if the `connection://...` string could be split across multiple `data` events? https://github.com/llvm/llvm-project/pull/128957 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits