[Lldb-commits] [lldb] [lldb-dap] Add process picker command to VS Code extension (PR #197513)
Sergei Druzhkov via lldb-commits
lldb-commits at lists.llvm.org
Fri May 15 01:44:08 PDT 2026
================
@@ -0,0 +1,132 @@
+import { execFile } from "node:child_process";
+import * as path from "node:path";
+import { promisify } from "node:util";
+import * as vscode from "vscode";
+
+import { createDebugAdapterExecutable } from "../debug-adapter-factory";
+import { LogFilePathProvider } from "../logging";
+import { LldbDapProcessTree, Process } from "../process-tree";
+
+const exec = promisify(execFile);
+
+/**
+ * Cache of which lldb-dap binaries have been observed to support the
+ * `--list-processes` flag, keyed by executable path. We probe once per path,
+ * but only remember successful probes — a transient failure (binary still
+ * building, EBUSY, etc.) should not poison the cache for the rest of the
+ * session.
+ */
+const listProcessesSupportCache = new Map<string, Promise<boolean>>();
+
+/** Probes `<exe> --help` to see whether `--list-processes` is advertised. */
+function isListProcessesSupported(exe: string): Promise<boolean> {
+ const cached = listProcessesSupportCache.get(exe);
+ if (cached) {
+ return cached;
+ }
+ const probe = exec(exe, ["--help"]).then(({ stdout }) =>
+ /--list-processes/.test(stdout),
+ );
+ listProcessesSupportCache.set(exe, probe);
+ // Drop failed probes so the next attempt can retry.
+ probe.catch(() => {
+ if (listProcessesSupportCache.get(exe) === probe) {
+ listProcessesSupportCache.delete(exe);
+ }
+ });
+ return probe.catch(() => false);
+}
+
+interface ProcessQuickPick extends vscode.QuickPickItem {
+ processId: number;
+}
+
+/**
+ * Prompts the user to select a running process, enumerated by `lldb-dap
+ * --list-processes`. When invoked from `resolveDebugConfiguration` the caller
+ * forwards the in-flight configuration so we can target the right lldb-dap
+ * binary and platform (for remote attach).
+ *
+ * @returns the pid of the selected process, or `undefined` if the user
+ * cancelled or the picker failed (in which case an error has already been
+ * shown).
+ */
+export async function pickProcess(
+ logger: vscode.LogOutputChannel,
+ logFilePath: LogFilePathProvider,
+ folder?: vscode.WorkspaceFolder,
+ debugConfiguration?: vscode.DebugConfiguration,
+): Promise<number | undefined> {
+ const executable = await createDebugAdapterExecutable(
+ logger,
+ logFilePath,
+ folder,
+ debugConfiguration ?? {
+ type: "lldb-dap",
+ request: "attach",
+ name: "Attach",
+ },
+ );
+
+ if (!(await isListProcessesSupported(executable.command))) {
+ await vscode.window.showErrorMessage(
+ "The lldb-dap binary does not support the --list-processes flag " +
+ "required by the process picker. Please update to a newer version.",
+ { modal: true, detail: executable.command },
+ );
+ return undefined;
+ }
+
+ const tree = new LldbDapProcessTree(executable.command, {
+ platformName: debugConfiguration?.platformName,
+ platformUrl: debugConfiguration?.platformUrl,
----------------
DrSergei wrote:
I think we should add mention of `platformUrl` into package.json
https://github.com/llvm/llvm-project/pull/197513
More information about the lldb-commits
mailing list