[Lldb-commits] [lldb] Complete the Implementation of DAP modules explorer. (PR #139934)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Wed May 14 13:15:43 PDT 2025
https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/139934
>From 7dbd5f7467cf1ab31caf935633062a7a66a49757 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Wed, 14 May 2025 17:32:47 +0100
Subject: [PATCH 1/4] [lldb][lldb-dap] clarify the todo.
---
lldb/tools/lldb-dap/package.json | 14 +++
lldb/tools/lldb-dap/src-ts/extension.ts | 10 +-
.../src-ts/ui/modules-data-provider.ts | 98 ++++++++++++-------
3 files changed, 85 insertions(+), 37 deletions(-)
diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index e3e46526f379f..3c73534fd3180 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -244,6 +244,20 @@
}
}
],
+ "commands": [
+ {
+ "command": "lldb-dap.modules.copyProperty",
+ "title": "Copy Value"
+ }
+ ],
+ "menus": {
+ "view/item/context": [
+ {
+ "command": "lldb-dap.modules.copyProperty",
+ "when": "view == lldb-dap.modules && viewItem == property"
+ }
+ ]
+ },
"breakpoints": [
{
"language": "ada"
diff --git a/lldb/tools/lldb-dap/src-ts/extension.ts b/lldb/tools/lldb-dap/src-ts/extension.ts
index a5c0a09ae60cf..c8e5146e29cea 100644
--- a/lldb/tools/lldb-dap/src-ts/extension.ts
+++ b/lldb/tools/lldb-dap/src-ts/extension.ts
@@ -6,7 +6,10 @@ import { LaunchUriHandler } from "./uri-launch-handler";
import { LLDBDapConfigurationProvider } from "./debug-configuration-provider";
import { LLDBDapServer } from "./lldb-dap-server";
import { DebugSessionTracker } from "./debug-session-tracker";
-import { ModulesDataProvider } from "./ui/modules-data-provider";
+import {
+ ModulesDataProvider,
+ ModuleProperty,
+} from "./ui/modules-data-provider";
/**
* This class represents the extension and manages its life cycle. Other extensions
@@ -40,6 +43,11 @@ export class LLDBDapExtension extends DisposableContext {
),
vscode.window.registerUriHandler(new LaunchUriHandler()),
);
+
+ vscode.commands.registerCommand(
+ "lldb-dap.modules.copyProperty",
+ (node: ModuleProperty) => vscode.env.clipboard.writeText(node.value),
+ );
}
}
diff --git a/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts b/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
index 478c162de8878..da527b04ba509 100644
--- a/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
+++ b/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
@@ -2,60 +2,86 @@ import * as vscode from "vscode";
import { DebugProtocol } from "@vscode/debugprotocol";
import { DebugSessionTracker } from "../debug-session-tracker";
-/** A tree data provider for listing loaded modules for the active debug session. */
-export class ModulesDataProvider
- implements vscode.TreeDataProvider<DebugProtocol.Module>
-{
- private changeTreeData = new vscode.EventEmitter<void>();
- readonly onDidChangeTreeData = this.changeTreeData.event;
+export interface ModuleProperty {
+ key: string;
+ value: string;
+}
- constructor(private readonly tracker: DebugSessionTracker) {
- tracker.onDidChangeModules(() => this.changeTreeData.fire());
- vscode.debug.onDidChangeActiveDebugSession(() =>
- this.changeTreeData.fire(),
- );
+/** Type to represent both Module and ModuleProperty since TreeDataProvider
+ * expects one concrete type */
+type TreeData = DebugProtocol.Module | ModuleProperty;
+
+function isModule(type: TreeData): type is DebugProtocol.Module {
+ return (type as DebugProtocol.Module).id !== undefined;
+}
+
+class ModuleItem extends vscode.TreeItem {
+ constructor(module: DebugProtocol.Module) {
+ super(module.name, vscode.TreeItemCollapsibleState.Collapsed);
+ this.description = module.symbolStatus;
}
- getTreeItem(module: DebugProtocol.Module): vscode.TreeItem {
- let treeItem = new vscode.TreeItem(/*label=*/ module.name);
- if (module.path) {
- treeItem.description = `${module.id} -- ${module.path}`;
- } else {
- treeItem.description = `${module.id}`;
- }
+ static getProperties(module: DebugProtocol.Module): ModuleProperty[] {
+ // does not include the name and symbol status as it is show in the parent.
+ let children: ModuleProperty[] = [];
+ children.push({ key: "id:", value: module.id.toString() });
- const tooltip = new vscode.MarkdownString();
- tooltip.appendMarkdown(`# ${module.name}\n\n`);
- tooltip.appendMarkdown(`- **ID**: ${module.id}\n`);
if (module.addressRange) {
- tooltip.appendMarkdown(
- `- **Load address**: 0x${Number(module.addressRange).toString(16)}\n`,
- );
+ children.push({
+ key: "load address:",
+ value: `0x${Number(module.addressRange).toString(16)}`,
+ });
}
if (module.path) {
- tooltip.appendMarkdown(`- **Path**: ${module.path}\n`);
+ children.push({ key: "path:", value: module.path });
}
if (module.version) {
- tooltip.appendMarkdown(`- **Version**: ${module.version}\n`);
- }
- if (module.symbolStatus) {
- tooltip.appendMarkdown(`- **Symbol status**: ${module.symbolStatus}\n`);
+ children.push({ key: "version:", value: module.version });
}
if (module.symbolFilePath) {
- tooltip.appendMarkdown(
- `- **Symbol file path**: ${module.symbolFilePath}\n`,
- );
+ children.push({ key: "symbol filepath:", value: module.symbolFilePath });
+ }
+ return children;
+ }
+}
+
+/** A tree data provider for listing loaded modules for the active debug session. */
+export class ModulesDataProvider implements vscode.TreeDataProvider<TreeData> {
+ private changeTreeData = new vscode.EventEmitter<void>();
+ readonly onDidChangeTreeData = this.changeTreeData.event;
+
+ constructor(private readonly tracker: DebugSessionTracker) {
+ tracker.onDidChangeModules(() => this.changeTreeData.fire());
+ vscode.debug.onDidChangeActiveDebugSession(() =>
+ this.changeTreeData.fire(),
+ );
+ }
+
+ getTreeItem(module: TreeData): vscode.TreeItem {
+ if (isModule(module)) {
+ return new ModuleItem(module);
}
- treeItem.tooltip = tooltip;
- return treeItem;
+ let item = new vscode.TreeItem(module.key);
+ item.description = module.value;
+ item.tooltip = `${module.key} ${module.value}`;
+ item.contextValue = "property";
+ return item;
}
- getChildren(): DebugProtocol.Module[] {
+ getChildren(element?: TreeData): TreeData[] {
if (!vscode.debug.activeDebugSession) {
return [];
}
- return this.tracker.debugSessionModules(vscode.debug.activeDebugSession);
+ if (!element) {
+ return this.tracker.debugSessionModules(vscode.debug.activeDebugSession);
+ }
+
+ if (isModule(element)) {
+ return ModuleItem.getProperties(element);
+ }
+
+ return [];
}
}
>From 3a5576d0e7380c434cdfdf64620f8b3a73c33bb5 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Wed, 14 May 2025 17:59:58 +0100
Subject: [PATCH 2/4] [lldb][lldb-dap] show load address in hex for all
dap-clients.
---
lldb/tools/lldb-dap/JSONUtils.cpp | 7 +++++--
lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 279e6d3d93814..31eb91f9f6b61 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -416,8 +416,11 @@ llvm::json::Value CreateModule(lldb::SBTarget &target, lldb::SBModule &module,
} else {
object.try_emplace("symbolStatus", "Symbols not found.");
}
- std::string loaded_addr = std::to_string(
- module.GetObjectFileHeaderAddress().GetLoadAddress(target));
+ std::string loaded_addr;
+ llvm::raw_string_ostream os_hex(loaded_addr);
+ os_hex << llvm::format_hex(
+ module.GetObjectFileHeaderAddress().GetLoadAddress(target),
+ sizeof(lldb::addr_t));
object.try_emplace("addressRange", loaded_addr);
std::string version_str;
uint32_t version_nums[3];
diff --git a/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts b/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
index da527b04ba509..091c1d69ac647 100644
--- a/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
+++ b/lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
@@ -29,7 +29,7 @@ class ModuleItem extends vscode.TreeItem {
if (module.addressRange) {
children.push({
key: "load address:",
- value: `0x${Number(module.addressRange).toString(16)}`,
+ value: module.addressRange,
});
}
if (module.path) {
>From 5adba9bd7a078b28ac48a7c69633c7bdbbabe2e8 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Wed, 14 May 2025 20:01:02 +0100
Subject: [PATCH 3/4] [lldb][lldb-dap] add review changes.
---
lldb/tools/lldb-dap/JSONUtils.cpp | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 31eb91f9f6b61..a8bd672583a5d 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -416,12 +416,11 @@ llvm::json::Value CreateModule(lldb::SBTarget &target, lldb::SBModule &module,
} else {
object.try_emplace("symbolStatus", "Symbols not found.");
}
- std::string loaded_addr;
- llvm::raw_string_ostream os_hex(loaded_addr);
- os_hex << llvm::format_hex(
- module.GetObjectFileHeaderAddress().GetLoadAddress(target),
- sizeof(lldb::addr_t));
- object.try_emplace("addressRange", loaded_addr);
+ std::string load_address =
+ llvm::formatv("{0:x}",
+ module.GetObjectFileHeaderAddress().GetLoadAddress(target))
+ .str();
+ object.try_emplace("addressRange", load_address);
std::string version_str;
uint32_t version_nums[3];
uint32_t num_versions =
>From e155adb23d79938a2c609fc63081b6b9f45db8d0 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Wed, 14 May 2025 21:15:25 +0100
Subject: [PATCH 4/4] [lldb][lldb-dap] do not show copy context in the command
palette
---
lldb/tools/lldb-dap/package.json | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lldb/tools/lldb-dap/package.json b/lldb/tools/lldb-dap/package.json
index 3c73534fd3180..d5ca604798799 100644
--- a/lldb/tools/lldb-dap/package.json
+++ b/lldb/tools/lldb-dap/package.json
@@ -251,6 +251,12 @@
}
],
"menus": {
+ "commandPalette": [
+ {
+ "command": "lldb-dap.modules.copyProperty",
+ "when": "false"
+ }
+ ],
"view/item/context": [
{
"command": "lldb-dap.modules.copyProperty",
More information about the lldb-commits
mailing list