Skip to content

Commit 0e0ea71

Browse files
authored
[vscode-lldb] Add VS Code commands for high level debug workflow (#151827)
This allows other debugger extensions to leverage the `lldb-dap` extension's settings and logic (e.g. "Server Mode"). Other debugger extensions can invoke these commands to resolve configuration, create adapter descriptor, and get the `lldb-dap` process for state tracking, additional interaction, and telemetry. VS Code commands added: * `lldb-dap.resolveDebugConfiguration` * `lldb-dap.resolveDebugConfigurationWithSubstitutedVariables` * `lldb-dap.createDebugAdapterDescriptor` * `lldb-dap.getServerProcess`
1 parent a418fa7 commit 0e0ea71

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

lldb/docs/resources/lldbdap.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,26 @@ This is also very simple, just run:
170170
```bash
171171
npm run format
172172
```
173+
174+
## Working with the VS Code extension from another extension
175+
176+
The VS Code extension exposes the following [VS Code
177+
commands](https://code.visualstudio.com/api/extension-guides/command),
178+
which can be invoked by other debugger extensions to leverage this extension's
179+
settings and logic. The commands help resolve configuration, create adapter
180+
descriptor, and get the lldb-dap process for state tracking, additional
181+
interaction, and telemetry.
182+
183+
```
184+
// Resolve debug configuration
185+
const resolvedConfiguration = await vscode.commands.executeCommand("lldb-dap.resolveDebugConfiguration", folder, configuration, token);
186+
187+
// Resolve debug configuration with substituted variables
188+
const resolvedConfigurationWithSubstitutedVariables = await vscode.commands.executeCommand("lldb-dap.resolveDebugConfigurationWithSubstitutedVariables", folder, configuration, token);
189+
190+
// Create debug adapter descriptor
191+
const adapterDescriptor = await vscode.commands.executeCommand("lldb-dap.createDebugAdapterDescriptor", session, executable);
192+
193+
// Get DAP server process
194+
const process = await vscode.commands.executeCommand("lldb-dap.getServerProcess");
195+
```

lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,15 @@ export class LLDBDapDescriptorFactory
217217
constructor(
218218
private readonly logger: vscode.LogOutputChannel,
219219
private logFilePath: LogFilePathProvider,
220-
) {}
220+
) {
221+
vscode.commands.registerCommand(
222+
"lldb-dap.createDebugAdapterDescriptor",
223+
(
224+
session: vscode.DebugSession,
225+
executable: vscode.DebugAdapterExecutable | undefined,
226+
) => this.createDebugAdapterDescriptor(session, executable),
227+
);
228+
}
221229

222230
async createDebugAdapterDescriptor(
223231
session: vscode.DebugSession,

lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,29 @@ export class LLDBDapConfigurationProvider
7676
private readonly server: LLDBDapServer,
7777
private readonly logger: vscode.LogOutputChannel,
7878
private readonly logFilePath: LogFilePathProvider,
79-
) {}
79+
) {
80+
vscode.commands.registerCommand(
81+
"lldb-dap.resolveDebugConfiguration",
82+
(
83+
folder: vscode.WorkspaceFolder | undefined,
84+
debugConfiguration: vscode.DebugConfiguration,
85+
token?: vscode.CancellationToken,
86+
) => this.resolveDebugConfiguration(folder, debugConfiguration, token),
87+
);
88+
vscode.commands.registerCommand(
89+
"lldb-dap.resolveDebugConfigurationWithSubstitutedVariables",
90+
(
91+
folder: vscode.WorkspaceFolder | undefined,
92+
debugConfiguration: vscode.DebugConfiguration,
93+
token?: vscode.CancellationToken,
94+
) =>
95+
this.resolveDebugConfigurationWithSubstitutedVariables(
96+
folder,
97+
debugConfiguration,
98+
token,
99+
),
100+
);
101+
}
80102

81103
async resolveDebugConfiguration(
82104
folder: vscode.WorkspaceFolder | undefined,

lldb/tools/lldb-dap/src-ts/lldb-dap-server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ export class LLDBDapServer implements vscode.Disposable {
1212
private serverProcess?: child_process.ChildProcessWithoutNullStreams;
1313
private serverInfo?: Promise<{ host: string; port: number }>;
1414

15+
constructor() {
16+
vscode.commands.registerCommand(
17+
"lldb-dap.getServerProcess",
18+
() => this.serverProcess,
19+
);
20+
}
21+
1522
/**
1623
* Starts the server with the provided options. The server will be restarted or reused as
1724
* necessary.

0 commit comments

Comments
 (0)