Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[lldb-dap] Adding defaults to VSCode settings for user level defaults. #137694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 2, 2025

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented Apr 28, 2025

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

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.
@llvmbot
Copy link
Member

llvmbot commented Apr 28, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

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 --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,

@ashgti
Copy link
Contributor Author

ashgti commented Apr 28, 2025

@eronnen this should resolve #134564

@eronnen
Copy link
Contributor

eronnen commented Apr 28, 2025

Nice!!

@ashgti ashgti requested a review from walter-erquinigo April 28, 2025 19:35
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.

Can you update the part of the README that talks about these settings and explain the precedence between the launch/attach configuration and the settings? It'd be nice to give some guidance so folks know where to configure things based on their needs. Otherwise this LGTM.

@ashgti
Copy link
Contributor Author

ashgti commented Apr 29, 2025

Fixed up the readme a little (mostly spelling fixes) and added a section describing user settings defaults.

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.

Thank you!

@da-viper
Copy link
Contributor

I don't think we need the defaults in in the setting string as it makes more sense to type
lldb-dap.commandEscapePrefix instead of lldb-dap.defaults.commandEscapePrefix

@da-viper
Copy link
Contributor

looks like this image

…esentation in the UI and adding an explicit 'order'.
@ashgti
Copy link
Contributor Author

ashgti commented Apr 29, 2025

Okay, how about this, I updated the settings to break things into 2 categories "Adapter" settings and "Defaults".

This is presented in the UI like this

Screenshot 2025-04-29 at 1 36 36 PM

And removes defaults from the settings keys.

Copy link
Contributor

@da-viper da-viper left a comment

Choose a reason for hiding this comment

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

LGTM

@ashgti ashgti merged commit 39e6e88 into llvm:main May 2, 2025
8 of 9 checks passed
@ashgti ashgti deleted the lldb-dap-settings branch May 2, 2025 16:06
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
llvm#137694)

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 llvm#134564
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
llvm#137694)

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 llvm#134564
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
llvm#137694)

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 llvm#134564
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
llvm#137694)

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 llvm#134564
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.

[lldb-dap] global initCommands settings for vscode extension
5 participants