[Lldb-commits] [lldb] [lldb-dap] expand tilde in dap executable path (PR #162635)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 31 08:27:31 PDT 2025
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/162635
>From c62a3532785cc0b5a72475a965ba4a99404432ba Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 9 Oct 2025 12:04:09 +0100
Subject: [PATCH 1/2] [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<Boolean> {
try {
await fs.access(path, fs.constants.X_OK);
@@ -116,8 +127,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 +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<string>("executable-path");
+ const configPath = expandUser(config.get<string>("executable-path") ?? "");
if (configPath && configPath.length !== 0) {
if (!(await isExecutable(configPath))) {
throw new ErrorWithNotification(
>From 4c25214fa0ee77292e32987584c4557845006bda Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Fri, 31 Oct 2025 15:26:59 +0000
Subject: [PATCH 2/2] [lldb-dap] add test case
---
lldb/tools/lldb-dap/package.json | 5 ++-
.../lldb-dap/src-ts/debug-adapter-factory.ts | 12 +----
lldb/tools/lldb-dap/src-ts/utils.ts | 41 +++++++++++++++++
lldb/tools/lldb-dap/tsconfig.json | 5 ++-
.../lldb-dap/unittests-ts/expandUser.test.ts | 45 +++++++++++++++++++
5 files changed, 94 insertions(+), 14 deletions(-)
create mode 100644 lldb/tools/lldb-dap/src-ts/utils.ts
create mode 100644 lldb/tools/lldb-dap/unittests-ts/expandUser.test.ts
diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index e961c2e48b258..6c0212e0869a9 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -31,6 +31,7 @@
"chokidar": "^4.0.3"
},
"devDependencies": {
+ "@types/mocha": "^10.0.1",
"@types/node": "^18.19.41",
"@types/tabulator-tables": "^6.2.10",
"@types/vscode": "1.75.0",
@@ -38,6 +39,7 @@
"@vscode/debugprotocol": "^1.68.0",
"@vscode/vsce": "^3.2.2",
"esbuild": "^0.25.9",
+ "mocha": "^10.2.0",
"prettier": "^3.4.2",
"prettier-plugin-curly": "^0.3.1",
"tabulator-tables": "^6.3.1",
@@ -53,9 +55,10 @@
"bundle-symbols-table-view": "npx tsc -p src-ts/webview --noEmit && npx esbuild src-ts/webview/symbols-table-view.ts --bundle --format=iife --outdir=./out/webview",
"bundle-tabulator": "cp node_modules/tabulator-tables/dist/js/tabulator.min.js ./out/webview/ && cp node_modules/tabulator-tables/dist/css/tabulator_midnight.min.css ./out/webview/ && cp node_modules/tabulator-tables/dist/css/tabulator_simple.min.css ./out/webview/",
"bundle-webview": "npm run bundle-symbols-table-view && npm run bundle-tabulator",
+ "check-unit": "npx tsc -p ./ && mocha ./out/unittests-ts",
"vscode:prepublish": "npm run bundle-webview && npm run bundle-extension",
"watch": "npm run bundle-webview && tsc -watch -p ./",
- "format": "npx prettier './src-ts/' --write",
+ "format": "npx prettier './src-ts/' './unittests-ts' --write",
"package": "rm -rf ./out && vsce package --out ./out/lldb-dap.vsix",
"publish": "vsce publish",
"vscode-uninstall": "code --uninstall-extension llvm-vs-code-extensions.lldb-dap",
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 c34f8866fb2e3..433d48fab9d85 100644
--- a/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
+++ b/lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
@@ -1,4 +1,3 @@
-import * as os from "os";
import * as path from "path";
import * as util from "util";
import * as vscode from "vscode";
@@ -7,19 +6,10 @@ 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);
-/**
- * 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<Boolean> {
try {
await fs.access(path, fs.constants.X_OK);
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;
+}
diff --git a/lldb/tools/lldb-dap/tsconfig.json b/lldb/tools/lldb-dap/tsconfig.json
index 06a484a1fc263..215b1d493e052 100644
--- a/lldb/tools/lldb-dap/tsconfig.json
+++ b/lldb/tools/lldb-dap/tsconfig.json
@@ -3,13 +3,14 @@
"moduleResolution": "node",
"module": "commonjs",
"outDir": "out",
- "rootDir": "src-ts",
+ "rootDirs": ["src-ts", "unittests-ts"],
"sourceMap": true,
"strict": true,
"target": "es6"
},
"include": [
- "src-ts"
+ "src-ts",
+ "unittests-ts"
],
"exclude": [
"node_modules",
diff --git a/lldb/tools/lldb-dap/unittests-ts/expandUser.test.ts b/lldb/tools/lldb-dap/unittests-ts/expandUser.test.ts
new file mode 100644
index 0000000000000..0fefbb025c2c8
--- /dev/null
+++ b/lldb/tools/lldb-dap/unittests-ts/expandUser.test.ts
@@ -0,0 +1,45 @@
+import { suite, test, suiteSetup, suiteTeardown } from "mocha";
+import * as assert from "assert";
+import * as os from "os";
+import * as process from "process";
+import { expandUser } from "../src-ts/utils";
+
+suite("expandUser Test", function () {
+ let home_env: { [key: string]: string | undefined } = {};
+ const local_username = os.userInfo().username;
+
+ suiteSetup(function () {
+ if (os.platform() == "win32") {
+ this.skip();
+ }
+ home_env.HOME = process.env.HOME;
+ process.env.HOME = "/home/buildbot";
+ });
+
+ suiteTeardown(function () {
+ process.env.HOME = home_env.HOME;
+ });
+
+ test("tilde ", function () {
+ assert.equal(expandUser("~"), "/home/buildbot");
+ assert.equal(expandUser("~/"), "/home/buildbot/");
+ assert.equal(expandUser("~/worker"), "/home/buildbot/worker");
+ });
+
+ test("tilde with username", function () {
+ assert.equal(expandUser(`~${local_username}`), "/home/buildbot");
+ assert.equal(expandUser(`~${local_username}/`), "/home/buildbot/");
+ assert.equal(expandUser(`~${local_username}/dev`), "/home/buildbot/dev");
+
+ // test unknown user
+ assert.notEqual(expandUser("~not_a_user"), "/home/build/bot");
+ });
+
+ test("empty", function () {
+ assert.equal(expandUser(""), "");
+ });
+
+ test("no tilde", function () {
+ assert.equal(expandUser("/home/buildbot/worker"), "/home/buildbot/worker");
+ });
+});
More information about the lldb-commits
mailing list