[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
Matthew Bastien via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 20 15:04:00 PDT 2025
================
@@ -90,117 +99,119 @@ async function getDAPExecutable(
return foundPath;
}
- return undefined;
+ throw new ErrorWithNotification(
+ "Unable to find the path to the LLDB debug adapter executable.",
+ new OpenSettingsButton("lldb-dap.executable-path"),
+ );
}
-async function isServerModeSupported(exe: string): Promise<boolean> {
- const { stdout } = await exec(exe, ['--help']);
- return /--connection/.test(stdout);
+/**
+ * Retrieves the arguments that will be provided to lldb-dap either from settings or the provided
+ * {@link vscode.DebugConfiguration}.
+ *
+ * @param workspaceFolder The {@link vscode.WorkspaceFolder} that the debug session will be launched within
+ * @param configuration The {@link vscode.DebugConfiguration} that will be launched
+ * @throws An {@link ErrorWithNotification} if something went wrong
+ * @returns The arguments that will be provided to lldb-dap
+ */
+async function getDAPArguments(
+ workspaceFolder: vscode.WorkspaceFolder | undefined,
+ configuration: vscode.DebugConfiguration,
+): Promise<string[]> {
+ // Check the debug configuration for arguments first.
+ const debugConfigArgs = configuration.debugAdapterArgs;
+ if (debugConfigArgs) {
+ if (
+ !Array.isArray(debugConfigArgs) ||
+ debugConfigArgs.findIndex((entry) => typeof entry !== "string") !== -1
+ ) {
+ throw new ErrorWithNotification(
+ "The debugAdapterArgs property must be an array of string values. Please update your launch configuration",
+ new ConfigureButton(),
+ );
+ }
+ return debugConfigArgs;
+ }
+ // Fall back on the workspace configuration.
+ return vscode.workspace
+ .getConfiguration("lldb-dap", workspaceFolder)
+ .get<string[]>("arguments", []);
+}
+
+/**
+ * Creates a new {@link vscode.DebugAdapterExecutable} based on the provided workspace folder and
+ * debug configuration. Assumes that the given debug configuration is for a local launch of lldb-dap.
+ *
+ * @param workspaceFolder The {@link vscode.WorkspaceFolder} that the debug session will be launched within
+ * @param configuration The {@link vscode.DebugConfiguration} that will be launched
+ * @throws An {@link ErrorWithNotification} if something went wrong
+ * @returns The {@link vscode.DebugAdapterExecutable} that can be used to launch lldb-dap
+ */
+export async function createDebugAdapterExecutable(
+ workspaceFolder: vscode.WorkspaceFolder | undefined,
+ configuration: vscode.DebugConfiguration,
+): Promise<vscode.DebugAdapterExecutable> {
+ const config = vscode.workspace.getConfiguration("lldb-dap", workspaceFolder);
+ const log_path = config.get<string>("log-path");
+ let env: { [key: string]: string } = {};
+ if (log_path) {
+ env["LLDBDAP_LOG"] = log_path;
+ }
+ const configEnvironment =
+ config.get<{ [key: string]: string }>("environment") || {};
+ const dapPath = await getDAPExecutable(workspaceFolder, configuration);
+
+ if (!(await isExecutable(dapPath))) {
+ let message = `Debug adapter path "${dapPath}" is not a valid file.`;
+ let buttons: (OpenSettingsButton | ConfigureButton)[] = [
+ new OpenSettingsButton("lldb-dap.executable-path"),
+ ];
+ if ("debugAdapterPath" in configuration) {
+ message += " The path comes from your launch configuration.";
+ buttons = [new ConfigureButton()];
+ }
+ throw new ErrorWithNotification(message, ...buttons);
+ }
----------------
matthewbastien wrote:
Good point. I've moved this logic into `getDAPExecutable()`.
https://github.com/llvm/llvm-project/pull/129262
More information about the lldb-commits
mailing list