From c62a3532785cc0b5a72475a965ba4a99404432ba Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Thu, 9 Oct 2025 12:04:09 +0100 Subject: [PATCH] [lldb-dap] expand tilde in dap executable path Users may have multiple devices and would like to resolve the homepath based on the machine they are on. --- .../lldb-dap/src-ts/debug-adapter-factory.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 7060638a94864..c34f8866fb2e3 100644 --- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts +++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts @@ -1,3 +1,4 @@ +import * as os from "os"; import * as path from "path"; import * as util from "util"; import * as vscode from "vscode"; @@ -9,6 +10,16 @@ import { LogFilePathProvider, LogType } from "./logging"; const exec = util.promisify(child_process.execFile); +/** + * Expands the character `~` to the user's home directory + */ +function expandUser(file_path: string): string { + if (file_path.startsWith("~")) { + return os.homedir() + file_path.slice(1); + } + return file_path; +} + async function isExecutable(path: string): Promise { try { await fs.access(path, fs.constants.X_OK); @@ -116,8 +127,9 @@ async function getDAPExecutable( configuration: vscode.DebugConfiguration, ): Promise { // Check if the executable was provided in the launch configuration. - const launchConfigPath = configuration["debugAdapterExecutable"]; + let launchConfigPath = configuration["debugAdapterExecutable"]; if (typeof launchConfigPath === "string" && launchConfigPath.length !== 0) { + launchConfigPath = expandUser(launchConfigPath); if (!(await isExecutable(launchConfigPath))) { throw new ErrorWithNotification( `Debug adapter path "${launchConfigPath}" is not a valid file. The path comes from your launch configuration.`, @@ -129,7 +141,7 @@ async function getDAPExecutable( // Check if the executable was provided in the extension's configuration. const config = vscode.workspace.getConfiguration("lldb-dap", workspaceFolder); - const configPath = config.get("executable-path"); + const configPath = expandUser(config.get("executable-path") ?? ""); if (configPath && configPath.length !== 0) { if (!(await isExecutable(configPath))) { throw new ErrorWithNotification(