Skip to content

Conversation

royitaqi
Copy link
Contributor

@royitaqi royitaqi commented Sep 11, 2025

Changes

#153536 added a new debug configuration field called debugAdapterEnv and enabled it in launch.json for launch requests. This patch enables the same for attach requests.

This patch also improves the regex used in this field, i.e. shortens it and fixes the double backslashes (\\) in debug-adapter-factory.ts (note: the ones in package.json need the double backslashes).

Test

Manually tested the following values in attach requests (so that we are testing both changes at the same time):

// Accepted
            "debugAdapterEnv": [
                "AAA=BBB",
            ],

            "debugAdapterEnv": [
                "AAA=",
            ],

            "debugAdapterEnv": [
                "AAA",
            ],

 // Rejected
            "debugAdapterEnv": [
                "=AAA",
            ],

            "debugAdapterEnv": [
                "=",
            ],

            "debugAdapterEnv": [
                "",
            ],

@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2025

@llvm/pr-subscribers-lldb

Author: Roy Shi (royitaqi)

Changes

Changes

#153536 added a new debug configuration field called debugAdapterEnv for the launch request. This patch adds the same for the attach request.

This patch also improves the regex used in this field, i.e. shortens it and fixed the double backslashes (\\) in debug-adapter-factory.ts (note: the ones in the package.json need the double backslashes).

Test

Manually tested the following field values with attach requests (so that we are testing both changes):

// Accepted
            "debugAdapterEnv": [
                "AAA=BBB",
            ],

            "debugAdapterEnv": [
                "AAA=",
            ],

            "debugAdapterEnv": [
                "AAA",
            ],

 // Rejected
            "debugAdapterEnv": [
                "=AAA",
            ],

            "debugAdapterEnv": [
                "=",
            ],

            "debugAdapterEnv": [
                "",
            ],

Full diff: https://github.com/llvm/llvm-project/pull/157980.diff

2 Files Affected:

  • (modified) lldb/tools/lldb-dap/package.json (+24-1)
  • (modified) lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts (+1-1)
diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index 9cc653cee405b..3d8b18bed0108 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -422,7 +422,7 @@
                     "markdownDescription": "Additional environment variables to set when launching the debug adapter executable. E.g. `[\"FOO=1\", \"BAR\"]`",
                     "items": {
                       "type": "string",
-                      "pattern": "^((\\w+=.*)|^\\w+)$"
+                      "pattern": "^\\w+(=.*)?$"
                     },
                     "default": []
                   }
@@ -672,6 +672,29 @@
                 },
                 "markdownDescription": "The list of additional arguments used to launch the debug adapter executable. Overrides any user or workspace settings."
               },
+              "debugAdapterEnv": {
+                "anyOf": [
+                  {
+                    "type": "object",
+                    "markdownDescription": "Additional environment variables to set when launching the debug adapter executable. E.g. `{ \"FOO\": \"1\" }`",
+                    "patternProperties": {
+                      ".*": {
+                        "type": "string"
+                      }
+                    },
+                    "default": {}
+                  },
+                  {
+                    "type": "array",
+                    "markdownDescription": "Additional environment variables to set when launching the debug adapter executable. E.g. `[\"FOO=1\", \"BAR\"]`",
+                    "items": {
+                      "type": "string",
+                      "pattern": "^\\w+(=.*)?$"
+                    },
+                    "default": []
+                  }
+                ]
+              },
               "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 f7e92ee95ca32..7060638a94864 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
@@ -92,7 +92,7 @@ function validateDAPEnv(debugConfigEnv: any): boolean {
     Array.isArray(debugConfigEnv) &&
     debugConfigEnv.findIndex(
       (entry) =>
-        typeof entry !== "string" || !/^((\\w+=.*)|^\\w+)$/.test(entry),
+        typeof entry !== "string" || !/^\w+(=.*)?$/.test(entry),
     ) !== -1
   ) {
     return false;

@royitaqi royitaqi changed the title [lldb-dap] Add debugAdapterEnv debug configuration field for attach requests, and improve regex [lldb-dap] Add debugAdapterEnv for attach requests & improve regex Sep 11, 2025
@royitaqi
Copy link
Contributor Author

@JDevlieghere / @walter-erquinigo: I will appreciate a quick review/stamp when you gentlemen have the time. Hopefully this doesn't cost more than 5 minutes.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@royitaqi royitaqi force-pushed the add-missing-debugAdapterEnv branch from eb85d54 to 68fdd63 Compare September 12, 2025 00:49
@royitaqi royitaqi merged commit 13daa1e into llvm:main Sep 12, 2025
9 checks passed
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Oct 14, 2025
llvm#157980)

# Changes

llvm#153536 added a new debug configuration field called `debugAdapterEnv`
and enabled it in `launch.json` **for `launch` requests**. This patch
enables the same for **`attach` requests**.

This patch also improves the regex used in this field, i.e. shortens it
and fixes the double backslashes (`\\`) in `debug-adapter-factory.ts`
(note: the ones in `package.json` need the double backslashes).

# Test

Manually tested the following values in `attach` requests (so that we
are testing both changes at the same time):
```
// Accepted
            "debugAdapterEnv": [
                "AAA=BBB",
            ],

            "debugAdapterEnv": [
                "AAA=",
            ],

            "debugAdapterEnv": [
                "AAA",
            ],

 // Rejected
            "debugAdapterEnv": [
                "=AAA",
            ],

            "debugAdapterEnv": [
                "=",
            ],

            "debugAdapterEnv": [
                "",
            ],
```

(cherry picked from commit 13daa1e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants