https://github.com/matthewbastien created 
https://github.com/llvm/llvm-project/pull/129262

Added a new setting called lldb-dap.arguments and a debug configuration 
attribute called debugAdapterArgs that can be used to set the arguments used to 
launch the debug adapter. Right now this is mostly useful for debugging 
purposes to add the `--wait-for-debugger` option to lldb-dap.

I've also removed the check for the `executable` argument in 
`LLDBDapDescriptorFactory.createDebugAdapterDescriptor()`. This argument is 
only set by VS Code when the debug adapter executable properties are set in the 
`package.json`. The LLDB DAP extension does not currently do this (and I don't 
think it ever will). So, this makes the debug adapter descriptor factory a 
little easier to read.

>From 8926756d800b9ecd171b6d645a459b01342e9458 Mon Sep 17 00:00:00 2001
From: Matthew Bastien <matthew_bast...@apple.com>
Date: Fri, 28 Feb 2025 11:08:25 -0500
Subject: [PATCH] allow providing debug adapter arguments

---
 lldb/tools/lldb-dap/package.json              | 23 +++++++++
 .../lldb-dap/src-ts/debug-adapter-factory.ts  | 48 +++++++++++--------
 2 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index 31d808eda4c35..0859b6e388a4e 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -75,6 +75,15 @@
           "type": "string",
           "description": "The path to the lldb-dap binary."
         },
+        "lldb-dap.arguments": {
+          "scope": "resource",
+          "type": "array",
+          "default": [],
+          "items": {
+            "type": "string"
+          },
+          "description": "The arguments provided to the lldb-dap process."
+        },
         "lldb-dap.log-path": {
           "scope": "resource",
           "type": "string",
@@ -156,6 +165,13 @@
                 "type": "string",
                 "markdownDescription": "The absolute path to the LLDB debug 
adapter executable to use."
               },
+              "debugAdapterArgs": {
+                "type": "array",
+                "items": {
+                  "type": "string"
+                },
+                "markdownDescription": "The list of arguments used to launch 
the debug adapter executable."
+              },
               "program": {
                 "type": "string",
                 "description": "Path to the program to debug."
@@ -346,6 +362,13 @@
                 "type": "string",
                 "markdownDescription": "The absolute path to the LLDB debug 
adapter executable to use."
               },
+              "debugAdapterArgs": {
+                "type": "array",
+                "items": {
+                  "type": "string"
+                },
+                "markdownDescription": "The list of arguments used to launch 
the debug adapter executable."
+              },
               "program": {
                 "type": "string",
                 "description": "Path to the program to attach to."
diff --git a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts 
b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
index 36107336ebc4d..ea7b4ce97ac1d 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
@@ -92,6 +92,21 @@ async function getDAPExecutable(
   return undefined;
 }
 
+function getDAPArguments(session: vscode.DebugSession): string[] {
+  // Check the debug configuration for arguments first
+  const debugConfigArgs = session.configuration.debugAdapterArgs;
+  if (
+    Array.isArray(debugConfigArgs) &&
+    debugConfigArgs.findIndex((entry) => typeof entry !== "string") === -1
+  ) {
+    return debugConfigArgs;
+  }
+  // Fall back on the workspace configuration
+  return vscode.workspace
+    .getConfiguration("lldb-dap")
+    .get<string[]>("arguments", []);
+}
+
 /**
  * This class defines a factory used to find the lldb-dap binary to use
  * depending on the session configuration.
@@ -101,7 +116,7 @@ export class LLDBDapDescriptorFactory
 {
   async createDebugAdapterDescriptor(
     session: vscode.DebugSession,
-    executable: vscode.DebugAdapterExecutable | undefined,
+    _executable: vscode.DebugAdapterExecutable | undefined,
   ): Promise<vscode.DebugAdapterDescriptor | undefined> {
     const config = vscode.workspace.getConfiguration(
       "lldb-dap",
@@ -116,40 +131,31 @@ export class LLDBDapDescriptorFactory
     const configEnvironment =
       config.get<{ [key: string]: string }>("environment") || {};
     const dapPath = await getDAPExecutable(session);
+    const dapArgs = getDAPArguments(session);
     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,
-      );
+    if (dapPath === undefined || !(await isExecutable(dapPath))) {
+      LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath);
+      return undefined;
     }
-    return undefined;
+    return new vscode.DebugAdapterExecutable(dapPath, dapArgs, dbgOptions);
   }
 
   /**
    * Shows a message box when the debug adapter's path is not found
    */
-  static async showLLDBDapNotFoundMessage(path: string) {
+  static async showLLDBDapNotFoundMessage(path: string | undefined) {
     const openSettingsAction = "Open Settings";
+    const message =
+      path === undefined
+        ? "Unable to find the LLDB debug adapter executable."
+        : `Debug adapter path: ${path} is not a valid file`;
     const callbackValue = await vscode.window.showErrorMessage(
-      `Debug adapter path: ${path} is not a valid file`,
+      message,
       openSettingsAction,
     );
 

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to