llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

<details>
<summary>Changes</summary>

This adds support for loading user level defaults in VSCode. The defaults are 
stored as basic settings that are loaded when the debug configuration is 
resolved. Not all settings are currently supported, I limited it to settings 
that would likely apply across multiple launch.json configurations.

This should resolve #<!-- -->134564

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


2 Files Affected:

- (modified) lldb/tools/lldb-dap/package.json (+106-1) 
- (modified) lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts (+81-3) 


``````````diff
diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index 1ef42b4a0d95c..d3efb5126e080 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -72,7 +72,6 @@
       "title": "lldb-dap",
       "properties": {
         "lldb-dap.executable-path": {
-          "scope": "resource",
           "type": "string",
           "scope": "machine-overridable",
           "description": "The path to the lldb-dap binary, e.g. 
/usr/local/bin/lldb-dap"
@@ -105,6 +104,112 @@
           "type": "boolean",
           "markdownDescription": "Run lldb-dap in server mode.\n\nWhen 
enabled, lldb-dap will start a background server that will be reused between 
debug sessions. This allows caching of debug symbols between sessions and 
improves launch performance.",
           "default": false
+        },
+        "lldb-dap.defaults.commandEscapePrefix": {
+          "type": "string",
+          "description": "The escape prefix to use for executing regular LLDB 
commands in the Debug Console, instead of printing variables. Defaults to a 
back-tick (`). If it's an empty string, then all expression in the Debug 
Console are treated as regular LLDB commands.",
+          "default": "`"
+        },
+        "lldb-dap.defaults.customFrameFormat": {
+          "type": "string",
+          "description": "If non-empty, stack frames will have descriptions 
generated based on the provided format. See 
https://lldb.llvm.org/use/formatting.html for an explanation on format strings 
for frames. If the format string contains errors, an error message will be 
displayed on the Debug Console and the default frame names will be used. This 
might come with a performance cost because debug information might need to be 
processed to generate the description.",
+          "default": ""
+        },
+        "lldb-dap.defaults.customThreadFormat": {
+          "type": "string",
+          "description": "If non-empty, threads will have descriptions 
generated based on the provided format. See 
https://lldb.llvm.org/use/formatting.html for an explanation on format strings 
for threads. If the format string contains errors, an error message will be 
displayed on the Debug Console and the default thread names will be used. This 
might come with a performance cost because debug information might need to be 
processed to generate the description.",
+          "default": ""
+        },
+        "lldb-dap.defaults.detachOnError": {
+          "type": "boolean",
+          "description": "Detach from the program.",
+          "default": false
+        },
+        "lldb-dap.defaults.disableASLR": {
+          "type": "boolean",
+          "description": "Enable or disable Address space layout randomization 
if the debugger supports it.",
+          "default": true
+        },
+        "lldb-dap.defaults.disableSTDIO": {
+          "type": "boolean",
+          "description": "Don't retrieve STDIN, STDOUT and STDERR as the 
program is running.",
+          "default": false
+        },
+        "lldb-dap.defaults.displayExtendedBacktrace": {
+          "type": "boolean",
+          "description": "Enable language specific extended backtraces.",
+          "default": false
+        },
+        "lldb-dap.defaults.enableAutoVariableSummaries": {
+          "type": "boolean",
+          "description": "Enable auto generated summaries for variables when 
no summaries exist for a given type. This feature can cause performance delays 
in large projects when viewing variables.",
+          "default": false
+        },
+        "lldb-dap.defaults.enableSyntheticChildDebugging": {
+          "type": "boolean",
+          "description": "If a variable is displayed using a synthetic 
children, also display the actual contents of the variable at the end under a 
[raw] entry. This is useful when creating sythetic child plug-ins as it lets 
you see the actual contents of the variable.",
+          "default": false
+        },
+        "lldb-dap.defaults.timeout": {
+          "type": "number",
+          "description": "The time in seconds to wait for a program to stop at 
entry point when launching with \"launchCommands\". Defaults to 30 seconds.",
+          "default": 30
+        },
+        "lldb-dap.defaults.targetTriple": {
+          "type": "string",
+          "description": "Triplet of the target architecture to override value 
derived from the program file."
+        },
+        "lldb-dap.defaults.platformName": {
+          "type": "string",
+          "description": "Name of the execution platform to override value 
derived from the program file."
+        },
+        "lldb-dap.defaults.initCommands": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "description": "Initialization commands executed upon debugger 
startup.",
+          "default": []
+        },
+        "lldb-dap.defaults.preRunCommands": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "description": "Commands executed just before the program is 
launched.",
+          "default": []
+        },
+        "lldb-dap.defaults.postRunCommands": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "description": "Commands executed just as soon as the program is 
successfully launched when it's in a stopped state prior to any automatic 
continuation.",
+          "default": []
+        },
+        "lldb-dap.defaults.stopCommands": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "description": "Commands executed each time the program stops.",
+          "default": []
+        },
+        "lldb-dap.defaults.exitCommands": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "description": "Commands executed when the program exits.",
+          "default": []
+        },
+        "lldb-dap.defaults.terminateCommands": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "description": "Commands executed when the debugging session ends.",
+          "default": []
         }
       }
     },
diff --git a/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts 
b/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts
index 8d92139c02a00..8a4089008b2f9 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts
@@ -20,10 +20,88 @@ async function isServerModeSupported(exe: string): 
Promise<boolean> {
   return /--connection/.test(stdout);
 }
 
+interface BoolConfig {
+  type: 'boolean';
+  default: boolean;
+}
+interface StringConfig {
+  type: 'string';
+  default: string;
+}
+interface NumberConfig {
+  type: 'number';
+  default: number;
+}
+interface StringArrayConfig {
+  type: 'stringArray';
+  default: string[];
+}
+type DefaultConfig = BoolConfig | NumberConfig | StringConfig | 
StringArrayConfig;
+
+const configurations: Record<string, DefaultConfig> = {
+  // Keys for debugger configurations.
+  "commandEscapePrefix": { type: "string", default: "`" },
+  "customFrameFormat": { type: "string", default: "" },
+  "customThreadFormat": { type: "string", default: "" },
+  "detachOnError": { type: "boolean", default: false },
+  "disableASLR": { type: "boolean", default: true },
+  "disableSTDIO": { type: "boolean", default: false },
+  "displayExtendedBacktrace": { type: "boolean", default: false },
+  "enableAutoVariableSummaries": { type: "boolean", default: false },
+  "enableSyntheticChildDebugging": { type: "boolean", default: false },
+  "timeout": { type: "number", default: 30 },
+
+  // Keys for platform / target configuration.
+  "platformName": { type: "string", default: "" },
+  "targetTriple": { type: "string", default: "" },
+
+  // Keys for debugger command hooks.
+  "initCommands": { type: "stringArray", default: [] },
+  "preRunCommands": { type: "stringArray", default: [] },
+  "postRunCommands": { type: "stringArray", default: [] },
+  "stopCommands": { type: "stringArray", default: [] },
+  "exitCommands": { type: "stringArray", default: [] },
+  "terminateCommands": { type: "stringArray", default: [] },
+};
+
 export class LLDBDapConfigurationProvider
-  implements vscode.DebugConfigurationProvider
-{
-  constructor(private readonly server: LLDBDapServer) {}
+  implements vscode.DebugConfigurationProvider {
+  constructor(private readonly server: LLDBDapServer) { }
+
+  async resolveDebugConfiguration(
+    folder: vscode.WorkspaceFolder | undefined,
+    debugConfiguration: vscode.DebugConfiguration,
+    token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration> {
+    let config = vscode.workspace.getConfiguration('lldb-dap.defaults');
+    for (const [key, cfg] of Object.entries(configurations)) {
+      if (Reflect.has(debugConfiguration, key)) continue;
+      const value = config.get(key);
+      if (value === cfg.default) continue;
+      switch (cfg.type) {
+        case 'string':
+          if (typeof value !== 'string')
+            throw new Error(`Expected ${key} to be a string, got ${value}`);
+          break;
+        case 'number':
+          if (typeof value !== 'number')
+            throw new Error(`Expected ${key} to be a number, got ${value}`);
+          break;
+        case 'boolean':
+          if (typeof value !== 'boolean')
+            throw new Error(`Expected ${key} to be a boolean, got ${value}`);
+          break;
+        case 'stringArray':
+          if (typeof value !== 'object' && Array.isArray(value))
+            throw new Error(`Expected ${key} to be a array of strings, got 
${value}`);
+          if ((value as string[]).length === 0) continue;
+          break;
+      }
+
+      debugConfiguration[key] = value;
+    }
+
+    return debugConfiguration;
+  }
 
   async resolveDebugConfigurationWithSubstitutedVariables(
     folder: vscode.WorkspaceFolder | undefined,

``````````

</details>


https://github.com/llvm/llvm-project/pull/137694
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to