Skip to content

[lldb-dap] Adding a modules explorer to lldb-dap ext. #138977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adjusting the modules tree view name and adding some documentation to…
… help explain the code a bit.
  • Loading branch information
ashgti committed May 7, 2025
commit da002083736f97692471d661cd31a64b37835205
4 changes: 2 additions & 2 deletions lldb/tools/lldb-dap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@
"views": {
"debug": [
{
"id": "lldb-dap.modulesExplorer",
"name": "LLDB Modules Explorer",
"id": "lldb-dap.modules",
"name": "Modules",
"when": "inDebugMode && debugType == 'lldb-dap'",
"icon": "$(symbol-module)"
}
Expand Down
24 changes: 23 additions & 1 deletion lldb/tools/lldb-dap/src-ts/debug-session-tracker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { DebugProtocol } from "@vscode/debugprotocol";
import * as vscode from "vscode";

/** A helper type for mapping event types to their corresponding data type. */
// prettier-ignore
interface EventMap {
module: DebugProtocol.ModuleEvent;
"module": DebugProtocol.ModuleEvent;
}

/** A type assertion to check if a ProtocolMessage is an event or if it is a specific event. */
function isEvent(
message: DebugProtocol.ProtocolMessage,
): message is DebugProtocol.Event;
Expand All @@ -22,11 +25,23 @@ function isEvent(
);
}

/** Tracks lldb-dap sessions for data visualizers. */
export class DebugSessionTracker
implements vscode.DebugAdapterTrackerFactory, vscode.Disposable
{
/**
* Tracks active modules for each debug sessions.
*
* The modules are kept in an array to maintain the load order of the modules.
*/
private modules = new Map<vscode.DebugSession, DebugProtocol.Module[]>();
private modulesChanged = new vscode.EventEmitter<void>();

/**
* Fired when modules are changed for any active debug session.
*
* Use `debugSessionModules` to retieve the active modules for a given debug session.
*/
onDidChangeModules: vscode.Event<void> = this.modulesChanged.event;

dispose() {
Expand All @@ -43,12 +58,19 @@ export class DebugSessionTracker
};
}

/**
* Retrieves the modules for the given debug session.
*
* Modules are returned in load order.
*/
debugSessionModules(session: vscode.DebugSession): DebugProtocol.Module[] {
return this.modules.get(session) ?? [];
}

/** Clear information from the active session. */
private onExit(session: vscode.DebugSession) {
this.modules.delete(session);
this.modulesChanged.fire();
}

private onDidSendMessage(
Expand Down
24 changes: 6 additions & 18 deletions lldb/tools/lldb-dap/src-ts/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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 { ModuleDataProvider } from "./ui/modules-data-provider";
import { ModulesDataProvider } from "./ui/modules-data-provider";

/**
* This class represents the extension and manages its life cycle. Other extensions
Expand All @@ -17,39 +17,27 @@ export class LLDBDapExtension extends DisposableContext {
super();

const lldbDapServer = new LLDBDapServer();
this.pushSubscription(lldbDapServer);
const sessionTracker = new DebugSessionTracker();

this.pushSubscription(
lldbDapServer,
sessionTracker,
vscode.debug.registerDebugConfigurationProvider(
"lldb-dap",
new LLDBDapConfigurationProvider(lldbDapServer),
),
);

this.pushSubscription(
vscode.debug.registerDebugAdapterDescriptorFactory(
"lldb-dap",
new LLDBDapDescriptorFactory(),
),
);

const sessionTracker = new DebugSessionTracker();

this.pushSubscription(
vscode.debug.registerDebugAdapterTrackerFactory(
"lldb-dap",
sessionTracker,
),
);

this.pushSubscription(
vscode.window.registerTreeDataProvider(
"lldb-dap.modulesExplorer",
new ModuleDataProvider(sessionTracker),
"lldb-dap.modules",
new ModulesDataProvider(sessionTracker),
),
);

this.pushSubscription(
vscode.window.registerUriHandler(new LaunchUriHandler()),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/src-ts/ui/modules-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as vscode from "vscode";
import { DebugProtocol } from "@vscode/debugprotocol";
import { DebugSessionTracker } from "../debug-session-tracker";

export class ModuleDataProvider
/** 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>();
Expand Down
Loading