Skip to content

Commit f687fdf

Browse files
allow providing debug adapter arguments
1 parent e93e0dd commit f687fdf

File tree

2 files changed

+76
-31
lines changed

2 files changed

+76
-31
lines changed

lldb/tools/lldb-dap/package.json

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@
7575
"type": "string",
7676
"description": "The path to the lldb-dap binary."
7777
},
78+
"lldb-dap.arguments": {
79+
"scope": "resource",
80+
"type": "array",
81+
"default": [],
82+
"items": {
83+
"type": "string"
84+
},
85+
"description": "The arguments provided to the lldb-dap process."
86+
},
7887
"lldb-dap.log-path": {
7988
"scope": "resource",
8089
"type": "string",
@@ -148,10 +157,6 @@
148157
{
149158
"type": "lldb-dap",
150159
"label": "LLDB DAP Debugger",
151-
"program": "./bin/lldb-dap",
152-
"windows": {
153-
"program": "./bin/lldb-dap.exe"
154-
},
155160
"configurationAttributes": {
156161
"launch": {
157162
"required": [
@@ -162,6 +167,13 @@
162167
"type": "string",
163168
"markdownDescription": "The absolute path to the LLDB debug adapter executable to use."
164169
},
170+
"debugAdapterArgs": {
171+
"type": "array",
172+
"items": {
173+
"type": "string"
174+
},
175+
"markdownDescription": "The list of arguments used to launch the debug adapter executable."
176+
},
165177
"program": {
166178
"type": "string",
167179
"description": "Path to the program to debug."
@@ -352,6 +364,13 @@
352364
"type": "string",
353365
"markdownDescription": "The absolute path to the LLDB debug adapter executable to use."
354366
},
367+
"debugAdapterArgs": {
368+
"type": "array",
369+
"items": {
370+
"type": "string"
371+
},
372+
"markdownDescription": "The list of arguments used to launch the debug adapter executable."
373+
},
355374
"program": {
356375
"type": "string",
357376
"description": "Path to the program to attach to."
@@ -549,4 +568,4 @@
549568
}
550569
]
551570
}
552-
}
571+
}

lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise<string | undefined> {
2525
if (stdout) {
2626
return stdout.toString().trimEnd();
2727
}
28-
} catch (error) { }
28+
} catch (error) {}
2929
}
3030
return undefined;
3131
}
@@ -93,8 +93,23 @@ async function getDAPExecutable(
9393
return undefined;
9494
}
9595

96+
function getDAPArguments(session: vscode.DebugSession): string[] {
97+
// Check the debug configuration for arguments first
98+
const debugConfigArgs = session.configuration.debugAdapterArgs;
99+
if (
100+
Array.isArray(debugConfigArgs) &&
101+
debugConfigArgs.findIndex((entry) => typeof entry !== "string") === -1
102+
) {
103+
return debugConfigArgs;
104+
}
105+
// Fall back on the workspace configuration
106+
return vscode.workspace
107+
.getConfiguration("lldb-dap")
108+
.get<string[]>("arguments", []);
109+
}
110+
96111
async function isServerModeSupported(exe: string): Promise<boolean> {
97-
const { stdout } = await exec(exe, ['--help']);
112+
const { stdout } = await exec(exe, ["--help"]);
98113
return /--connection/.test(stdout);
99114
}
100115

@@ -103,8 +118,13 @@ async function isServerModeSupported(exe: string): Promise<boolean> {
103118
* depending on the session configuration.
104119
*/
105120
export class LLDBDapDescriptorFactory
106-
implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable {
107-
private server?: Promise<{ process: child_process.ChildProcess, host: string, port: number }>;
121+
implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable
122+
{
123+
private server?: Promise<{
124+
process: child_process.ChildProcess;
125+
host: string;
126+
port: number;
127+
}>;
108128

109129
dispose() {
110130
this.server?.then(({ process }) => {
@@ -114,7 +134,7 @@ export class LLDBDapDescriptorFactory
114134

115135
async createDebugAdapterDescriptor(
116136
session: vscode.DebugSession,
117-
executable: vscode.DebugAdapterExecutable | undefined,
137+
_executable: vscode.DebugAdapterExecutable | undefined,
118138
): Promise<vscode.DebugAdapterDescriptor | undefined> {
119139
const config = vscode.workspace.getConfiguration(
120140
"lldb-dap",
@@ -128,7 +148,7 @@ export class LLDBDapDescriptorFactory
128148
}
129149
const configEnvironment =
130150
config.get<{ [key: string]: string }>("environment") || {};
131-
const dapPath = (await getDAPExecutable(session)) ?? executable?.command;
151+
const dapPath = await getDAPExecutable(session);
132152

133153
if (!dapPath) {
134154
LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage();
@@ -142,54 +162,60 @@ export class LLDBDapDescriptorFactory
142162

143163
const dbgOptions = {
144164
env: {
145-
...executable?.options?.env,
146165
...configEnvironment,
147166
...env,
148167
},
149168
};
150-
const dbgArgs = executable?.args ?? [];
151-
152-
const serverMode = config.get<boolean>('serverMode', false);
153-
if (serverMode && await isServerModeSupported(dapPath)) {
154-
const { host, port } = await this.startServer(dapPath, dbgArgs, dbgOptions);
169+
const dbgArgs = getDAPArguments(session);
170+
171+
const serverMode = config.get<boolean>("serverMode", false);
172+
if (serverMode && (await isServerModeSupported(dapPath))) {
173+
const { host, port } = await this.startServer(
174+
dapPath,
175+
dbgArgs,
176+
dbgOptions,
177+
);
155178
return new vscode.DebugAdapterServer(port, host);
156179
}
157180

158181
return new vscode.DebugAdapterExecutable(dapPath, dbgArgs, dbgOptions);
159182
}
160183

161-
startServer(dapPath: string, args: string[], options: child_process.CommonSpawnOptions): Promise<{ host: string, port: number }> {
162-
if (this.server) return this.server;
184+
startServer(
185+
dapPath: string,
186+
args: string[],
187+
options: child_process.CommonSpawnOptions,
188+
): Promise<{ host: string; port: number }> {
189+
if (this.server) {
190+
return this.server;
191+
}
163192

164-
this.server = new Promise(resolve => {
165-
args.push(
166-
'--connection',
167-
'connect://localhost:0'
168-
);
193+
this.server = new Promise((resolve) => {
194+
args.push("--connection", "connect://localhost:0");
169195
const server = child_process.spawn(dapPath, args, options);
170-
server.stdout!.setEncoding('utf8').once('data', (data: string) => {
196+
server.stdout!.setEncoding("utf8").once("data", (data: string) => {
171197
const connection = /connection:\/\/\[([^\]]+)\]:(\d+)/.exec(data);
172198
if (connection) {
173199
const host = connection[1];
174200
const port = Number(connection[2]);
175201
resolve({ process: server, host, port });
176202
}
177203
});
178-
server.on('exit', () => {
204+
server.on("exit", () => {
179205
this.server = undefined;
180-
})
206+
});
181207
});
182208
return this.server;
183209
}
184210

185211
/**
186212
* Shows a message box when the debug adapter's path is not found
187213
*/
188-
static async showLLDBDapNotFoundMessage(path?: string) {
214+
static async showLLDBDapNotFoundMessage(path?: string | undefined) {
189215
const message =
190-
path
191-
? `Debug adapter path: ${path} is not a valid file.`
192-
: "Unable to find the path to the LLDB debug adapter executable.";
216+
path !== undefined
217+
? `Debug adapter path: ${path} is not a valid file`
218+
: "Unable to find the LLDB debug adapter executable.";
193219
const openSettingsAction = "Open Settings";
194220
const callbackValue = await vscode.window.showErrorMessage(
195221
message,

0 commit comments

Comments
 (0)