[Lldb-commits] [lldb] [lldb-dap] expand tilde in dap executable path (PR #162635)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 5 09:31:59 PST 2025
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/162635
>From 5c20782303773eb366f96d52ab11a05347e89d47 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Wed, 5 Nov 2025 17:28:09 +0000
Subject: [PATCH] [lldb-dap] expand tilde in dap executable path
---
.../lldb-dap/src-ts/debug-adapter-factory.ts | 6 ++-
lldb/tools/lldb-dap/src-ts/utils.ts | 41 +++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
create mode 100644 lldb/tools/lldb-dap/src-ts/utils.ts
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..433d48fab9d85 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
@@ -6,6 +6,7 @@ import * as fs from "node:fs/promises";
import { ConfigureButton, OpenSettingsButton } from "./ui/show-error-message";
import { ErrorWithNotification } from "./ui/error-with-notification";
import { LogFilePathProvider, LogType } from "./logging";
+import { expandUser } from "./utils";
const exec = util.promisify(child_process.execFile);
@@ -116,8 +117,9 @@ async function getDAPExecutable(
configuration: vscode.DebugConfiguration,
): Promise<string> {
// 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 +131,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<string>("executable-path");
+ const configPath = expandUser(config.get<string>("executable-path") ?? "");
if (configPath && configPath.length !== 0) {
if (!(await isExecutable(configPath))) {
throw new ErrorWithNotification(
diff --git a/lldb/tools/lldb-dap/src-ts/utils.ts b/lldb/tools/lldb-dap/src-ts/utils.ts
new file mode 100644
index 0000000000000..efebe0b0f42ba
--- /dev/null
+++ b/lldb/tools/lldb-dap/src-ts/utils.ts
@@ -0,0 +1,41 @@
+import * as os from "os";
+import * as path from "path";
+
+/**
+ * Expands the character `~` to the user's home directory
+ */
+export function expandUser(file_path: string): string {
+ if (os.platform() == "win32") {
+ return file_path;
+ }
+
+ if (!file_path) {
+ return "";
+ }
+
+ if (!file_path.startsWith("~")) {
+ return file_path;
+ }
+
+ const path_len = file_path.length;
+ if (path_len == 1) {
+ return os.homedir();
+ }
+
+ if (file_path.charAt(1) == path.sep) {
+ return path.join(os.homedir(), file_path.substring(1));
+ }
+
+ const sep_index = file_path.indexOf(path.sep);
+ const user_name_end = sep_index == -1 ? file_path.length : sep_index;
+ const user_name = file_path.substring(1, user_name_end);
+ try {
+ if (user_name == os.userInfo().username) {
+ return path.join(os.homedir(), file_path.substring(user_name_end));
+ }
+ } catch (err) {
+ return file_path;
+ }
+
+ return file_path;
+}
More information about the lldb-commits
mailing list