[Lldb-commits] [lldb] [lldb-dap] Adding server mode support to lldb-dap VSCode extension. (PR #128957)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 28 19:19:00 PST 2025
================
@@ -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) => {
----------------
ashgti wrote:
A single 'data' event usually corresponds to a single 'write' event which https://github.com/llvm/llvm-project/blob/cef6dbbe544ff4c49fca65cdc50df783d8c39c28/lldb/tools/lldb-dap/lldb-dap.cpp#L298 should correspond to one call.
https://github.com/llvm/llvm-project/pull/128957
More information about the lldb-commits
mailing list