[Lldb-commits] [lldb] [lldb-dap] add `debugAdapterExecutable` property to launch configuration (PR #126803)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/126803 >From a07148100b02fa109cd3131d2d7742cdc0ae2bfa Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Tue, 11 Feb 2025 16:38:43 -0500 Subject: [PATCH 1/2] add `debugAdapterExecutable` property to launch configuration --- lldb/tools/lldb-dap/package.json| 10 +- lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts | 9 +++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index e866af0602d70..d45c78432fa23 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -86,7 +86,7 @@ "default": {}, "description": "The environment of the lldb-dap process.", "additionalProperties": { - "type": "string" +"type": "string" } } } @@ -152,6 +152,10 @@ "program" ], "properties": { + "debugAdapterExecutable": { +"type": "string", +"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." + }, "program": { "type": "string", "description": "Path to the program to debug." @@ -338,6 +342,10 @@ }, "attach": { "properties": { + "debugAdapterExecutable": { +"type": "string", +"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." + }, "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 55c2f3e9f7deb..e1c6bd4fd4300 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -67,12 +67,17 @@ async function findDAPExecutable(): Promise { async function getDAPExecutable( session: vscode.DebugSession, ): Promise { + // Check if the executable was provided in the launch configuration. + const launchConfigPath = session.configuration["debugAdapterExecutable"]; + if (typeof launchConfigPath === "string" && launchConfigPath.length !== 0) { +return launchConfigPath; + } + + // Check if the executable was provided in the extension's configuration. const config = vscode.workspace.getConfiguration( "lldb-dap", session.workspaceFolder, ); - - // Prefer the explicitly specified path in the extension's configuration. const configPath = config.get("executable-path"); if (configPath && configPath.length !== 0) { return configPath; >From 28b9097c12de0b3ef5fe4f083c54ff5d0963c6c7 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 12 Feb 2025 10:32:36 -0500 Subject: [PATCH 2/2] reword description of debugAdapterExecutable --- lldb/tools/lldb-dap/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index d45c78432fa23..edcae59867b53 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -154,7 +154,7 @@ "properties": { "debugAdapterExecutable": { "type": "string", -"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." +"markdownDescription": "The absolute path to the LLDB debug adapter executable to use." }, "program": { "type": "string", @@ -344,7 +344,7 @@ "properties": { "debugAdapterExecutable": { "type": "string", -"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." +"markdownDescription": "The absolute path to the LLDB debug adapter executable to use." }, "program": { "type": "string", ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] add `debugAdapterExecutable` property to launch configuration (PR #126803)
@@ -152,6 +152,10 @@ "program" ], "properties": { + "debugAdapterExecutable": { +"type": "string", +"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." matthewbastien wrote: Good catch. I changed the wording to make it clear that this must be an absolute path to the executable. https://github.com/llvm/llvm-project/pull/126803 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Only include necessary files in the lldb-dap VSIX (PR #124986)
https://github.com/matthewbastien created https://github.com/llvm/llvm-project/pull/124986 The published VSIX for the LLDB DAP extension contains a bunch of unnecessary files: ``` ❯ tar tf llvm-vs-code-extensions.lldb-dap-0.2.8.vsix extension.vsixmanifest [Content_Types].xml extension/.github/workflows/auto_publish.yml extension/.github/workflows/integrate_llvmproject.yml extension/.gitignore extension/.vscode/launch.json extension/.vscode/tasks.json extension/LICENSE.TXT extension/out/debug-adapter-factory.js extension/out/debug-adapter-factory.js.map extension/out/disposable-context.js extension/out/disposable-context.js.map extension/out/extension.js extension/out/extension.js.map extension/out/types.js extension/out/types.js.map extension/package.json extension/README.md extension/src-ts/debug-adapter-factory.ts extension/src-ts/disposable-context.ts extension/src-ts/extension.ts extension/src-ts/types.ts extension/syntaxes/arm.disasm extension/syntaxes/arm64.disasm extension/syntaxes/disassembly.json extension/syntaxes/x86.disasm extension/tsconfig.json ``` All that's really needed is the package.json, license, README, syntaxes folder, and compiled sources. This PR adds a `.vscodeignore` file that requires files and directories to be explicitly added to the VSIX. >From d98d57a5f0df75aee5196e3e4046a7f68f4dc0d6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 29 Jan 2025 16:02:11 -0500 Subject: [PATCH] only include necessary files in the lldb-dap VSIX --- lldb/tools/lldb-dap/.vscodeignore | 9 + 1 file changed, 9 insertions(+) create mode 100644 lldb/tools/lldb-dap/.vscodeignore diff --git a/lldb/tools/lldb-dap/.vscodeignore b/lldb/tools/lldb-dap/.vscodeignore new file mode 100644 index 00..0491ba879fc3f0 --- /dev/null +++ b/lldb/tools/lldb-dap/.vscodeignore @@ -0,0 +1,9 @@ +// Ignore everything by default +**/* + +// Only include specific files and directories +!LICENSE.TXT +!package.json +!README.md +!out/** +!syntaxes/** ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Only include necessary files in the lldb-dap VSIX (PR #124986)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/124986 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Only include necessary files in the lldb-dap VSIX (PR #124986)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/124986 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Only include necessary files in the lldb-dap VSIX (PR #124986)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/124986 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] add `debugAdapterExecutable` property to launch configuration (PR #126803)
https://github.com/matthewbastien created https://github.com/llvm/llvm-project/pull/126803 The Swift extension for VS Code requires that the `lldb-dap` executable come from the Swift toolchain which may or may not be configured in `PATH`. At the moment, this can be configured via LLDB DAP's extension settings, but experience has shown that modifying other extensions' settings on behalf of the user (especially those subject to change whenever a new toolchain is selected) causes issues. Instead, it would be easier to have this configurable in the launch configuration and let the Swift extension (or any other extension that wanted to, really) configure the path to `lldb-dap` that way. This allows the Swift extension to have its own launch configuration type that delegates to the LLDB DAP extension in order to provide a more seamless debugging experience for Swift executables. This PR adds a new property to the launch configuration object called `debugAdapterExecutable` which allows overriding the `lldb-dap` executable path for a specific debug session. >From 830a56acf776046d65dada631b54c74ed2aa5f87 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Tue, 11 Feb 2025 16:38:43 -0500 Subject: [PATCH] add `debugAdapterExecutable` property to launch configuration --- lldb/tools/lldb-dap/package.json| 6 +- lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts | 9 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index e866af0602d70..fb4a828795041 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -86,7 +86,7 @@ "default": {}, "description": "The environment of the lldb-dap process.", "additionalProperties": { - "type": "string" +"type": "string" } } } @@ -152,6 +152,10 @@ "program" ], "properties": { + "debugAdapterExecutable": { +"type": "string", +"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." + }, "program": { "type": "string", "description": "Path to the program to debug." 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 55c2f3e9f7deb..e1c6bd4fd4300 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -67,12 +67,17 @@ async function findDAPExecutable(): Promise { async function getDAPExecutable( session: vscode.DebugSession, ): Promise { + // Check if the executable was provided in the launch configuration. + const launchConfigPath = session.configuration["debugAdapterExecutable"]; + if (typeof launchConfigPath === "string" && launchConfigPath.length !== 0) { +return launchConfigPath; + } + + // Check if the executable was provided in the extension's configuration. const config = vscode.workspace.getConfiguration( "lldb-dap", session.workspaceFolder, ); - - // Prefer the explicitly specified path in the extension's configuration. const configPath = config.get("executable-path"); if (configPath && configPath.length !== 0) { return configPath; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] add `debugAdapterExecutable` property to launch configuration (PR #126803)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/126803 >From a07148100b02fa109cd3131d2d7742cdc0ae2bfa Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Tue, 11 Feb 2025 16:38:43 -0500 Subject: [PATCH] add `debugAdapterExecutable` property to launch configuration --- lldb/tools/lldb-dap/package.json| 10 +- lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts | 9 +++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index e866af0602d70..d45c78432fa23 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -86,7 +86,7 @@ "default": {}, "description": "The environment of the lldb-dap process.", "additionalProperties": { - "type": "string" +"type": "string" } } } @@ -152,6 +152,10 @@ "program" ], "properties": { + "debugAdapterExecutable": { +"type": "string", +"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." + }, "program": { "type": "string", "description": "Path to the program to debug." @@ -338,6 +342,10 @@ }, "attach": { "properties": { + "debugAdapterExecutable": { +"type": "string", +"markdownDescription": "The LLDB debug adapter executable to use. Either an absolute path or the name of a debug adapter executable available on the `PATH`." + }, "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 55c2f3e9f7deb..e1c6bd4fd4300 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -67,12 +67,17 @@ async function findDAPExecutable(): Promise { async function getDAPExecutable( session: vscode.DebugSession, ): Promise { + // Check if the executable was provided in the launch configuration. + const launchConfigPath = session.configuration["debugAdapterExecutable"]; + if (typeof launchConfigPath === "string" && launchConfigPath.length !== 0) { +return launchConfigPath; + } + + // Check if the executable was provided in the extension's configuration. const config = vscode.workspace.getConfiguration( "lldb-dap", session.workspaceFolder, ); - - // Prefer the explicitly specified path in the extension's configuration. const configPath = config.get("executable-path"); if (configPath && configPath.length !== 0) { return configPath; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien created https://github.com/llvm/llvm-project/pull/128943 Adds a process picker command to the LLDB DAP extension that will prompt the user to select a process running on their machine. It is hidden from the command palette, but can be used in an `"attach"` debug configuration to select a process at the start of a debug session. I've also added a debug configuration snippet for this called `"LLDB: Attach to Process"` that will fill in the appropriate variable substitution. e.g: ```json { "type": "lldb-dap", "request": "attach", "name": "Attach to Process", "pid": "${command:PickProcess}" } ``` The logic is largely the same as the process picker in the `vscode-js-debug` extension created by Microsoft. It will use available executables based on the current platform to find the list of available processes: - **Linux**: uses the `ps` executable to list processes. - **macOS**: nearly identical to Linux except that the command line options passed to `ps` are different - **Windows**: uses `WMIC.exe` to query WMI for processes I manually tested this on a MacBook Pro running macOS Sequoia, a Windows 11 VM, and an Ubuntu 22.04 VM. Fixes #96279 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/2] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisf
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/3] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/null
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/4] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/null
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
matthewbastien wrote: Yeah, the CodeLLDB extension uses `lldb` to print the processes for the current platform (which could be a possibility as well, though then you'd also have to have an option to specify the `lldb` executable alongside `lldb-dap`). I'd rather have a NodeJS approach if only because relying on a specific version of `lldb-dap` won't really work for Swift until it updates its version of `lldb-dap` meaning that the functionality probably won't be available until Swift 6.2. I'd prefer to have it available sooner since we'd like to switch away from CodeLLDB as soon as possible. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From 8926756d800b9ecd171b6d645a459b01342e9458 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/2] 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("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 { 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 pat
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From 8926756d800b9ecd171b6d645a459b01342e9458 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/2] 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("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 { 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 pat
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -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." matthewbastien wrote: No reason in particular. You're right. I've updated the wording with your suggestions. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -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`; matthewbastien wrote: Good call. This is the only place that we show notifications as far as I can tell. So, I'm leaning towards having the period at the end and changed both to match. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From 8926756d800b9ecd171b6d645a459b01342e9458 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/2] 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("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 { 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 pat
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/5] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/null
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,102 @@ +import { ChildProcessWithoutNullStreams } from "child_process"; +import { Process, ProcessTree } from "."; +import { Transform } from "stream"; + +/** Parses process information from a given line of process output. */ +export type ProcessTreeParser = (line: string) => Process | undefined; + +/** + * Implements common behavior between the different {@link ProcessTree} implementations. + */ +export abstract class BaseProcessTree implements ProcessTree { + /** + * Spawn the process responsible for collecting all processes on the system. + */ + protected abstract spawnProcess(): ChildProcessWithoutNullStreams; matthewbastien wrote: I normally prefer `spawn()` because you can specify arguments separately, but since we're passing any user input to the spawned process, `exec()` definitely makes more sense to simplify the logic here. Thanks for the suggestion! I've updated the PR. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,38 @@ +import { ChildProcessWithoutNullStreams, spawn } from "child_process"; +import { BaseProcessTree, ProcessTreeParser } from "../base-process-tree"; + +export class LinuxProcessTree extends BaseProcessTree { + protected override spawnProcess(): ChildProcessWithoutNullStreams { +return spawn( + "ps", + ["-axo", `pid=PID,lstart=START,comm:128=COMMAND,command=ARGUMENTS`], + { +stdio: "pipe", + }, matthewbastien wrote: No longer exists with change to `exec()`. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/5] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/null
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From b40c3e7e4ebb154c5f231676451acbd17e1f39f7 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/2] allow providing debug adapter arguments --- lldb/tools/lldb-dap/package.json | 23 ++ .../lldb-dap/src-ts/debug-adapter-factory.ts | 72 +-- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index cd450a614b3f7..aa11d8bcaa66e 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", @@ -162,6 +171,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." @@ -352,6 +368,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 1f76fe31b00ad..51f45f87d660a 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise { if (stdout) { return stdout.toString().trimEnd(); } -} catch (error) { } +} catch (error) {} } return undefined; } @@ -93,13 +93,33 @@ 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("arguments", []); +} + /** * This class defines a factory used to find the lldb-dap binary to use * depending on the session configuration. */ export class LLDBDapDescriptorFactory - implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable { - private server?: Promise<{ process: child_process.ChildProcess, host: string, port: number }>; + implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable +{ + private server?: Promise<{ +process: child_process.ChildProcess; +host: string; +port: number; + }>; dispose() { this.server?.then(({ process }) => { @@ -109,7 +129,7 @@ export class LLDBDapDescriptorFactory async createDebugAdapterDescriptor( session: vscode.DebugSession, -executable: vscode.DebugAdapterExecutable | undefined, +_executable: vscode.DebugAdapterExecutable | undefined, ): Promise { const config = vscode.workspace.getConfiguration( "lldb-dap", @@ -123,7 +143,7 @@ export class LLDBDapDescriptorFactory } const configEnvironment = config.get<{ [key: string]: string }>("environment") || {}; -const dapPath = (await getDAPExecutable(session)) ?? executable?.command; +const dapPath = await getDAPExecutable(session); if (!dapPath) { LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(); @@ -137,32 +157,38 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/5] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/null
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 1/5] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/null
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,102 @@ +import { ChildProcessWithoutNullStreams } from "child_process"; +import { Process, ProcessTree } from "."; +import { Transform } from "stream"; + +/** Parses process information from a given line of process output. */ +export type ProcessTreeParser = (line: string) => Process | undefined; + +/** + * Implements common behavior between the different {@link ProcessTree} implementations. + */ +export abstract class BaseProcessTree implements ProcessTree { + /** + * Spawn the process responsible for collecting all processes on the system. + */ + protected abstract spawnProcess(): ChildProcessWithoutNullStreams; matthewbastien wrote: So it does! Fixed. Thanks! https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments (PR #129262)
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 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("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 { 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, [], dbgO
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,15 @@ +import { LinuxProcessTree } from "./linux-process-tree"; + +function fill(prefix: string, suffix: string, length: number): string { + return prefix + suffix.repeat(length - prefix.length); +} + +export class DarwinProcessTree extends LinuxProcessTree { + protected override getCommandArguments(): string[] { +return [ + "-xo", matthewbastien wrote: Good catch. Fixed. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,15 @@ +import { LinuxProcessTree } from "./linux-process-tree"; + +function fill(prefix: string, suffix: string, length: number): string { + return prefix + suffix.repeat(length - prefix.length); +} + +export class DarwinProcessTree extends LinuxProcessTree { + protected override getCommandArguments(): string[] { +return [ + "-xo", + // The length of comm must be large enough or data will be truncated. + `pid=PID,lstart=START,comm=${fill("COMMAND", "-", 256)},command=ARGUMENTS`, matthewbastien wrote: Unfortunately, the column names are different on Linux and macOS. So, this needs to stay. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/10] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,52 @@ +import * as path from "path"; +import { BaseProcessTree, ProcessTreeParser } from "../base-process-tree"; +import { ChildProcessWithoutNullStreams, spawn } from "child_process"; + +export class WindowsProcessTree extends BaseProcessTree { + protected override spawnProcess(): ChildProcessWithoutNullStreams { +const wmic = path.join( + process.env["WINDIR"] || "C:\\Windows", + "System32", + "wbem", + "WMIC.exe", matthewbastien wrote: Hm. I didn't know about that. I'll have to look at their alternatives. FWIW I do have a Windows 11 machine running the latest updates and it's working there. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/11] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" matthewbastien wrote: Done. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,52 @@ +import * as path from "path"; +import { BaseProcessTree, ProcessTreeParser } from "../base-process-tree"; +import { ChildProcessWithoutNullStreams, spawn } from "child_process"; + +export class WindowsProcessTree extends BaseProcessTree { + protected override spawnProcess(): ChildProcessWithoutNullStreams { +const wmic = path.join( + process.env["WINDIR"] || "C:\\Windows", + "System32", + "wbem", + "WMIC.exe", matthewbastien wrote: Looks like `Get-CimInstance` is the preferred method for future-proofing's sake. I've updated the `WindowsProcessTree` to use that instead. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/13] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/12] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -27,9 +28,14 @@ export class LinuxProcessTree extends BaseProcessTree { return; } + const command = line.slice(commandOffset, argumentsOffset).trim(); + if (command === "-") { matthewbastien wrote: Added the comment. When `ps` doesn't know where the executable is located it prints `-`. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -65,6 +65,18 @@ This will attach to a process `a.out` whose process ID is 123: } ``` +You can also use the variable substituion `${command:pickProcess}` to select a matthewbastien wrote: Fixed. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -65,6 +65,18 @@ This will attach to a process `a.out` whose process ID is 123: } ``` +You can also use the variable substituion `${command:pickProcess}` to select a +process at the start of the debug session instead of setting the pid manually: + +```javascript +{ + "type": "lldb-dap", + "request": "attach", + "name": "Attach to PID", + "pid": "${command:pickProcess}" +} +``` + matthewbastien wrote: Good point. I've updated the wording with your suggestion. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/14] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/15] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/16] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -65,6 +65,19 @@ This will attach to a process `a.out` whose process ID is 123: } ``` +You can also use the variable substituion `${command:PickProcess}` to select a +process at the start of the debug session instead of setting the pid manually: + +```javascript +{ + "type": "lldb-dap", + "request": "attach", + "name": "Attach to PID", + "program": "/tmp/a.out", matthewbastien wrote: Whoops. Copy and paste issue. Good catch! https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From b40c3e7e4ebb154c5f231676451acbd17e1f39f7 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/6] allow providing debug adapter arguments --- lldb/tools/lldb-dap/package.json | 23 ++ .../lldb-dap/src-ts/debug-adapter-factory.ts | 72 +-- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index cd450a614b3f7..aa11d8bcaa66e 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", @@ -162,6 +171,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." @@ -352,6 +368,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 1f76fe31b00ad..51f45f87d660a 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise { if (stdout) { return stdout.toString().trimEnd(); } -} catch (error) { } +} catch (error) {} } return undefined; } @@ -93,13 +93,33 @@ 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("arguments", []); +} + /** * This class defines a factory used to find the lldb-dap binary to use * depending on the session configuration. */ export class LLDBDapDescriptorFactory - implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable { - private server?: Promise<{ process: child_process.ChildProcess, host: string, port: number }>; + implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable +{ + private server?: Promise<{ +process: child_process.ChildProcess; +host: string; +port: number; + }>; dispose() { this.server?.then(({ process }) => { @@ -109,7 +129,7 @@ export class LLDBDapDescriptorFactory async createDebugAdapterDescriptor( session: vscode.DebugSession, -executable: vscode.DebugAdapterExecutable | undefined, +_executable: vscode.DebugAdapterExecutable | undefined, ): Promise { const config = vscode.workspace.getConfiguration( "lldb-dap", @@ -123,7 +143,7 @@ export class LLDBDapDescriptorFactory } const configEnvironment = config.get<{ [key: string]: string }>("environment") || {}; -const dapPath = (await getDAPExecutable(session)) ?? executable?.command; +const dapPath = await getDAPExecutable(session); if (!dapPath) { LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(); @@ -137,32 +157,38 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -34,6 +34,23 @@ function convertToInteger(value: any): number | undefined { export class LLDBDapConfigurationProvider implements vscode.DebugConfigurationProvider { + resolveDebugConfiguration( +_folder: vscode.WorkspaceFolder | undefined, +debugConfiguration: vscode.DebugConfiguration, +_token?: vscode.CancellationToken, + ): vscode.ProviderResult { +// Default "pid" to ${command:pickProcess} if neither "pid" nor "program" are specified +// in an "attach" request. +if ( + debugConfiguration.request === "attach" && + !("pid" in debugConfiguration) && + !("program" in debugConfiguration) +) { + debugConfiguration.pid = "${command:pickProcess}"; matthewbastien wrote: I've updated both of these to better reflect my changes. I did a pretty major overhaul of the `README` section on attaching and would appreciate another thorough review there to make sure the wording sounds good. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,42 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * The return value must be a string so that it is compatible with VS Code's + * string substitution infrastructure. The value will eventually be converted + * to a number by the debug configuration provider. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { matthewbastien wrote: I really like this idea! I've added a filter to the process picker if the `program` is also set. As a side note: I hadn't actually anticipated setting both `pid` and `program` at the same time. I accidentally left the `program` property in my example launch configuration. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/11] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
matthewbastien wrote: > You can go one level beyond this and provide a way to attach to programs > without needing launch.json configs at all! > > 1. Create a new pallete command "attach to process" > 2. Reuse the same process picker and once the user has selected one item, > issue a vscode.debug.StartDebugging() call passing a minimal debug config > with the selected process as PID. That's a great idea and simple to add! I've added a new command `LLDB DAP: Attach to process...` in the command palette. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/17] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,48 @@ +import * as path from "path"; +import { BaseProcessTree, ProcessTreeParser } from "../base-process-tree"; + +export class WindowsProcessTree extends BaseProcessTree { + protected override getCommand(): string { +return "PowerShell"; + } + + protected override getCommandArguments(): string[] { +return [ + "-Command", + 'Get-CimInstance -ClassName Win32_Process | Format-Table ProcessId, @{Label="CreationDate";Expression={"{0:MddHHmmss}" -f $_.CreationDate}}, CommandLine | Out-String -width ', matthewbastien wrote: Done. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -0,0 +1,16 @@ +import { ChildProcessWithoutNullStreams, spawn } from "child_process"; +import { LinuxProcessTree } from "./linux-process-tree"; + +function fill(prefix: string, suffix: string, length: number): string { matthewbastien wrote: Thanks! I didn't know about that function. Done. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -65,6 +65,19 @@ This will attach to a process `a.out` whose process ID is 123: } ``` +You can also use the variable substituion `${command:PickProcess}` to select a +process at the start of the debug session instead of setting the pid manually: + +```javascript +{ + "type": "lldb-dap", + "request": "attach", + "name": "Attach to PID", + "program": "/tmp/a.out", + "pid": "${command:PickProcess}" matthewbastien wrote: That's a nice feature to have. I've added logic to the `LLDBDapConfigurationProvider` that will set `pid` to `"${command:pickProcess}"` if neither `pid` nor `program` are specified in an `attach` request. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -34,6 +34,23 @@ function convertToInteger(value: any): number | undefined { export class LLDBDapConfigurationProvider implements vscode.DebugConfigurationProvider { + resolveDebugConfiguration( +_folder: vscode.WorkspaceFolder | undefined, +debugConfiguration: vscode.DebugConfiguration, +_token?: vscode.CancellationToken, + ): vscode.ProviderResult { +// Default "pid" to ${command:pickProcess} if neither "pid" nor "program" are specified +// in an "attach" request. +if ( + debugConfiguration.request === "attach" && + !("pid" in debugConfiguration) && matthewbastien wrote: Makes sense to me, though the process picker does conflict with the `waitFor` property, if set. I'm going to add a check for that instead. Quick question with regards to attach configurations, though: shouldn't the `program` be required for LLDB to properly load debug symbols? Or more simply: would it make any sense to debug a process without a `program` specified? I know the C/C++ extension does require the `program` property to be set. Seems like we should be doing the same. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -162,6 +171,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 additional arguments used to launch the debug adapter executable." matthewbastien wrote: Done. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From b40c3e7e4ebb154c5f231676451acbd17e1f39f7 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/4] allow providing debug adapter arguments --- lldb/tools/lldb-dap/package.json | 23 ++ .../lldb-dap/src-ts/debug-adapter-factory.ts | 72 +-- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index cd450a614b3f7..aa11d8bcaa66e 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", @@ -162,6 +171,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." @@ -352,6 +368,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 1f76fe31b00ad..51f45f87d660a 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise { if (stdout) { return stdout.toString().trimEnd(); } -} catch (error) { } +} catch (error) {} } return undefined; } @@ -93,13 +93,33 @@ 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("arguments", []); +} + /** * This class defines a factory used to find the lldb-dap binary to use * depending on the session configuration. */ export class LLDBDapDescriptorFactory - implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable { - private server?: Promise<{ process: child_process.ChildProcess, host: string, port: number }>; + implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable +{ + private server?: Promise<{ +process: child_process.ChildProcess; +host: string; +port: number; + }>; dispose() { this.server?.then(({ process }) => { @@ -109,7 +129,7 @@ export class LLDBDapDescriptorFactory async createDebugAdapterDescriptor( session: vscode.DebugSession, -executable: vscode.DebugAdapterExecutable | undefined, +_executable: vscode.DebugAdapterExecutable | undefined, ): Promise { const config = vscode.workspace.getConfiguration( "lldb-dap", @@ -123,7 +143,7 @@ export class LLDBDapDescriptorFactory } const configEnvironment = config.get<{ [key: string]: string }>("environment") || {}; -const dapPath = (await getDAPExecutable(session)) ?? executable?.command; +const dapPath = await getDAPExecutable(session); if (!dapPath) { LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(); @@ -137,32 +157,38 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -93,13 +93,33 @@ 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; + } matthewbastien wrote: Added an error message if `debugAdapterArgs` is not in the expected format. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -137,53 +157,59 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +const dbgArgs = getDAPArguments(session); -const serverMode = config.get('serverMode', false); +const serverMode = config.get("serverMode", false); if (serverMode) { - const { host, port } = await this.startServer(dapPath, dbgArgs, dbgOptions); + const { host, port } = await this.startServer( +dapPath, +dbgArgs, +dbgOptions, + ); return new vscode.DebugAdapterServer(port, host); } return new vscode.DebugAdapterExecutable(dapPath, dbgArgs, dbgOptions); } - startServer(dapPath: string, args: string[], options: child_process.CommonSpawnOptions): Promise<{ host: string, port: number }> { -if (this.server) return this.server; + startServer( +dapPath: string, +args: string[], +options: child_process.CommonSpawnOptions, + ): Promise<{ host: string; port: number }> { +if (this.server) { + return this.server; +} -this.server = new Promise(resolve => { - args.push( -'--connection', -'connect://localhost:0' - ); +this.server = new Promise((resolve) => { + args.push("--connection", "connect://localhost:0"); const server = child_process.spawn(dapPath, args, options); - server.stdout!.setEncoding('utf8').once('data', (data: string) => { + server.stdout!.setEncoding("utf8").once("data", (data: string) => { const connection = /connection:\/\/\[([^\]]+)\]:(\d+)/.exec(data); if (connection) { const host = connection[1]; const port = Number(connection[2]); resolve({ process: server, host, port }); } }); - server.on('exit', () => { + server.on("exit", () => { this.server = undefined; - }) + }); }); return this.server; } /** * Shows a message box when the debug adapter's path is not found */ - static async showLLDBDapNotFoundMessage(path?: string) { + static async showLLDBDapNotFoundMessage(path?: string | undefined) { matthewbastien wrote: Done. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -137,53 +157,59 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +const dbgArgs = getDAPArguments(session); -const serverMode = config.get('serverMode', false); +const serverMode = config.get("serverMode", false); if (serverMode) { - const { host, port } = await this.startServer(dapPath, dbgArgs, dbgOptions); + const { host, port } = await this.startServer( +dapPath, +dbgArgs, +dbgOptions, + ); return new vscode.DebugAdapterServer(port, host); } return new vscode.DebugAdapterExecutable(dapPath, dbgArgs, dbgOptions); } - startServer(dapPath: string, args: string[], options: child_process.CommonSpawnOptions): Promise<{ host: string, port: number }> { -if (this.server) return this.server; + startServer( +dapPath: string, +args: string[], +options: child_process.CommonSpawnOptions, + ): Promise<{ host: string; port: number }> { +if (this.server) { + return this.server; +} matthewbastien wrote: Alright, this took a bit of re-organizing since the `DebugAdapterDescriptorFactory` does not gracefully stop the debug session if it returns `undefined`. Instead, VS Code shows a modal with an error message that suggests that the extension may not have activated properly which is... unhelpful in this case. I've moved the logic for starting the server and prompting the user for input to a new `DebugConfigurationProvider` which can stop the session gracefully and even open the `launch.json` for editing if something goes wrong. In order to facilitate this, I had to add two new properties to the launch configuration that are used by the `DebugAdapterDescriptorFactory` to tell VS Code how to launch the debug adapter: - `debugAdapterHostname` - the hostname for an existing lldb-dap server - `debugAdapterPort `- the port for an existing lldb-dap server This has the added bonus of allowing the user to start their own lldb-dap process in server mode if they really wanted to. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From b40c3e7e4ebb154c5f231676451acbd17e1f39f7 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/5] allow providing debug adapter arguments --- lldb/tools/lldb-dap/package.json | 23 ++ .../lldb-dap/src-ts/debug-adapter-factory.ts | 72 +-- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index cd450a614b3f7..aa11d8bcaa66e 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", @@ -162,6 +171,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." @@ -352,6 +368,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 1f76fe31b00ad..51f45f87d660a 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise { if (stdout) { return stdout.toString().trimEnd(); } -} catch (error) { } +} catch (error) {} } return undefined; } @@ -93,13 +93,33 @@ 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("arguments", []); +} + /** * This class defines a factory used to find the lldb-dap binary to use * depending on the session configuration. */ export class LLDBDapDescriptorFactory - implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable { - private server?: Promise<{ process: child_process.ChildProcess, host: string, port: number }>; + implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable +{ + private server?: Promise<{ +process: child_process.ChildProcess; +host: string; +port: number; + }>; dispose() { this.server?.then(({ process }) => { @@ -109,7 +129,7 @@ export class LLDBDapDescriptorFactory async createDebugAdapterDescriptor( session: vscode.DebugSession, -executable: vscode.DebugAdapterExecutable | undefined, +_executable: vscode.DebugAdapterExecutable | undefined, ): Promise { const config = vscode.workspace.getConfiguration( "lldb-dap", @@ -123,7 +143,7 @@ export class LLDBDapDescriptorFactory } const configEnvironment = config.get<{ [key: string]: string }>("environment") || {}; -const dapPath = (await getDAPExecutable(session)) ?? executable?.command; +const dapPath = await getDAPExecutable(session); if (!dapPath) { LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(); @@ -137,32 +157,38 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -137,53 +157,59 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; matthewbastien wrote: Alright, this took a bit of re-organizing since the `DebugAdapterDescriptorFactory` does not gracefully stop the debug session if it returns `undefined`. Instead, VS Code shows a modal with an error message that suggests that the extension may not have activated properly which is... unhelpful in this case. I've moved the logic for starting the server and prompting the user for input to a new `DebugConfigurationProvider` which can stop the session gracefully and even open the `launch.json` for editing if something goes wrong. In order to facilitate this, I had to add two new properties to the launch configuration that are used by the `DebugAdapterDescriptorFactory` to tell VS Code how to launch the debug adapter: - `debugAdapterHostname` - the hostname for an existing lldb-dap server - `debugAdapterPort `- the port for an existing lldb-dap server This has the added bonus of allowing the user to start their own lldb-dap process in server mode if they really wanted to. The `DebugAdapterDescriptorFactory` will also throw an error if the executable parameter is set. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/20] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -34,6 +34,23 @@ function convertToInteger(value: any): number | undefined { export class LLDBDapConfigurationProvider implements vscode.DebugConfigurationProvider { + resolveDebugConfiguration( +_folder: vscode.WorkspaceFolder | undefined, +debugConfiguration: vscode.DebugConfiguration, +_token?: vscode.CancellationToken, + ): vscode.ProviderResult { +// Default "pid" to ${command:pickProcess} if neither "pid" nor "program" are specified +// in an "attach" request. +if ( + debugConfiguration.request === "attach" && + !("pid" in debugConfiguration) && matthewbastien wrote: Sounds like we can leave it optional then. I've updated the PR to always use the process picker except when `waitFor` is set to `true` as that appears to be handled by `lldb-dap` rather than the extension. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/21] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/128943 >From b9083ea16c7b1dba70cc04acf78f5001f0fb86c6 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Wed, 26 Feb 2025 11:18:21 -0500 Subject: [PATCH 01/23] add a process picker for attaching by PID --- lldb/tools/lldb-dap/package.json | 30 +- .../lldb-dap/src-ts/commands/pick-process.ts | 37 +++ lldb/tools/lldb-dap/src-ts/extension.ts | 7 +- .../src-ts/process-tree/base-process-tree.ts | 102 ++ .../lldb-dap/src-ts/process-tree/index.ts | 36 +++ .../platforms/darwin-process-tree.ts | 16 +++ .../platforms/linux-process-tree.ts | 38 +++ .../platforms/windows-process-tree.ts | 52 + 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 lldb/tools/lldb-dap/src-ts/commands/pick-process.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/index.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/darwin-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/linux-process-tree.ts create mode 100644 lldb/tools/lldb-dap/src-ts/process-tree/platforms/windows-process-tree.ts diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index 31d808eda4c35..1bbdbf045dd1b 100644 --- a/lldb/tools/lldb-dap/package.json +++ b/lldb/tools/lldb-dap/package.json @@ -146,6 +146,9 @@ "windows": { "program": "./bin/lldb-dap.exe" }, +"variables": { + "PickProcess": "lldb-dap.pickProcess" +}, "configurationAttributes": { "launch": { "required": [ @@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" +} + }, { "label": "LLDB: Attach", "description": "", @@ -541,6 +554,21 @@ } ] } -] +], +"commands": [ + { +"command": "lldb-dap.pickProcess", +"title": "Pick Process", +"category": "LLDB DAP" + } +], +"menus": { + "commandPalette": [ +{ + "command": "lldb-dap.pickProcess", + "when": "false" +} + ] +} } } diff --git a/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts new file mode 100644 index 0..b83e749e7da7b --- /dev/null +++ b/lldb/tools/lldb-dap/src-ts/commands/pick-process.ts @@ -0,0 +1,37 @@ +import * as path from "path"; +import * as vscode from "vscode"; +import { createProcessTree } from "../process-tree"; + +interface ProcessQuickPick extends vscode.QuickPickItem { + processId: number; +} + +/** + * Prompts the user to select a running process. + * + * @returns The pid of the process as a string or undefined if cancelled. + */ +export async function pickProcess(): Promise { + const processTree = createProcessTree(); + const selectedProcess = await vscode.window.showQuickPick( +processTree.listAllProcesses().then((processes): ProcessQuickPick[] => { + return processes +.sort((a, b) => b.start - a.start) // Sort by start date in descending order +.map((proc) => { + return { +processId: proc.id, +label: path.basename(proc.command), +description: proc.id.toString(), +detail: proc.arguments, + } satisfies ProcessQuickPick; +}); +}), +{ + placeHolder: "Select a process to attach the debugger to", +}, + ); + if (!selectedProcess) { +return; + } + return selectedProcess.processId.toString(); +} diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts index 71fd48298f8f5..3532a2143155b 100644 --- a/lldb/tools/lldb-dap/src-ts/extension.ts +++ b/lldb/tools/lldb-dap/src-ts/extension.ts @@ -1,7 +1,6 @@ -import * as path from "path"; -import * as util from "util"; import * as vscode from "vscode"; +import { pickProcess } from "./commands/pick-process"; import { LLDBDapDescriptorFactory, isExecutable, @@ -38,6 +37,10 @@ export class LLDBDapExtension extends DisposableContext { } }), ); + +this.pushSubscription( + vscode.commands.registerCommand("lldb-dap.pickProcess", pickProcess), +); } } diff --git a/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts b/lldb/tools/lldb-dap/src-ts/process-tree/base-process-tree.ts new file mode 100644 index 0..3c08f49035b35 --- /dev/nul
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien updated https://github.com/llvm/llvm-project/pull/129262 >From b40c3e7e4ebb154c5f231676451acbd17e1f39f7 Mon Sep 17 00:00:00 2001 From: Matthew Bastien Date: Fri, 28 Feb 2025 11:08:25 -0500 Subject: [PATCH 1/7] allow providing debug adapter arguments --- lldb/tools/lldb-dap/package.json | 23 ++ .../lldb-dap/src-ts/debug-adapter-factory.ts | 72 +-- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json index cd450a614b3f7..aa11d8bcaa66e 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", @@ -162,6 +171,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." @@ -352,6 +368,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 1f76fe31b00ad..51f45f87d660a 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise { if (stdout) { return stdout.toString().trimEnd(); } -} catch (error) { } +} catch (error) {} } return undefined; } @@ -93,13 +93,33 @@ 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("arguments", []); +} + /** * This class defines a factory used to find the lldb-dap binary to use * depending on the session configuration. */ export class LLDBDapDescriptorFactory - implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable { - private server?: Promise<{ process: child_process.ChildProcess, host: string, port: number }>; + implements vscode.DebugAdapterDescriptorFactory, vscode.Disposable +{ + private server?: Promise<{ +process: child_process.ChildProcess; +host: string; +port: number; + }>; dispose() { this.server?.then(({ process }) => { @@ -109,7 +129,7 @@ export class LLDBDapDescriptorFactory async createDebugAdapterDescriptor( session: vscode.DebugSession, -executable: vscode.DebugAdapterExecutable | undefined, +_executable: vscode.DebugAdapterExecutable | undefined, ): Promise { const config = vscode.workspace.getConfiguration( "lldb-dap", @@ -123,7 +143,7 @@ export class LLDBDapDescriptorFactory } const configEnvironment = config.get<{ [key: string]: string }>("environment") || {}; -const dapPath = (await getDAPExecutable(session)) ?? executable?.command; +const dapPath = await getDAPExecutable(session); if (!dapPath) { LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(); @@ -137,32 +157,38 @@ export class LLDBDapDescriptorFactory const dbgOptions = { env: { -...executable?.options?.env, ...configEnvironment, ...env, }, }; -const dbgArgs = executable?.args ?? []; +
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
@@ -66,19 +70,17 @@ async function findDAPExecutable(): Promise { } async function getDAPExecutable( - session: vscode.DebugSession, + folder: vscode.WorkspaceFolder | undefined, matthewbastien wrote: Done. https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
matthewbastien wrote: > I am not sure I understand that concern. Looking at the [commit log of > swiftlang/llvm-project](https://github.com/swiftlang/llvm-project/commits/next/lldb/tools/lldb-dap), > it seems that they are picking up changes to lldb-dap very quickly. Or am I > missing something? Swift uses specific branches of the name `stable/*` for its fork of `llvm-project`. At the moment, the Swift `main` branch builds use `stable/20240723` which has very few of the recent changes to `llvm/llvm-project` in it (and anything new needs to be cherry-picked in). Additionally, release builds of Swift are locked to a `swift/release/*` branch. Currently, Swift 6.1 is locked except for major bug fixes and uses the `swift/release/6.1` branch for builds. That being said, I still agree that adding the process picking functionality to `lldb-dap` makes the most sense in the long run. Especially for cases where remote debugging is being used. I'm going to add the NodeJS process picker to the Swift extension in order to support attach requests in Swift 6.0, but will work on updating this PR with the `lldb-dap` platform process list approach afterwards. Once this gets into Swift's `lldb-dap` then that extension can use the process picker from this PR. I think that's a happy medium in the meantime. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Allow providing debug adapter arguments in the extension (PR #129262)
https://github.com/matthewbastien edited https://github.com/llvm/llvm-project/pull/129262 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
matthewbastien wrote: One more thing that crossed my mind: given that the LLDB DAP extension will automatically be updated to the latest version by VS Code, should we also have feature flags for things like this in lldb-dap? (or is there some way already to detect which features are available?) The version of `lldb-dap` the user has installed will most likely not be the the absolute latest. In fact, I recently encountered an issue with the new `lldb-dap.serverMode` setting where enabling it caused the version of `lldb-dap` I have installed to hang since it doesn't actually support the `--connection` command line option. https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #128943)
@@ -517,6 +520,16 @@ "cwd": "^\"\\${workspaceRoot}\"" } }, + { +"label": "LLDB: Attach to Process", +"description": "", +"body": { + "type": "lldb-dap", + "request": "attach", + "name": "${1:Attach}", + "pid": "^\"\\${command:PickProcess}\"" matthewbastien wrote: Yeah, VS Code allows supplying your own variable substitutions. I've set this up in the `package.json` at line 150: ``` "variables": { "pickProcess": "lldb-dap.pickProcess" }, ``` https://github.com/llvm/llvm-project/pull/128943 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits