Skip to content

Commit b670ccb

Browse files
use LLDB DAP extension to launch debug sessions
1 parent acf8084 commit b670ccb

File tree

4 files changed

+11
-85
lines changed

4 files changed

+11
-85
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,8 @@
14591459
]
14601460
},
14611461
"extensionDependencies": [
1462-
"vadimcn.vscode-lldb"
1462+
"vadimcn.vscode-lldb",
1463+
"llvm-vs-code-extensions.lldb-dap"
14631464
],
14641465
"scripts": {
14651466
"vscode:prepublish": "npm run bundle",

src/debugger/debugAdapter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const SWIFT_LAUNCH_CONFIG_TYPE = "swift";
2727
* LLDB launch requests.
2828
*/
2929
export const enum LaunchConfigType {
30-
LLDB_DAP = "swift",
30+
LLDB_DAP = "lldb-dap",
3131
CODE_LLDB = "lldb",
3232
}
3333

src/debugger/debugAdapterFactory.ts

+2-45
Original file line numberDiff line numberDiff line change
@@ -52,54 +52,10 @@ function registerLLDBDebugAdapter(
5252
toolchain: SwiftToolchain,
5353
outputChannel: SwiftOutputChannel
5454
): vscode.Disposable {
55-
const debugAdpaterFactory = vscode.debug.registerDebugAdapterDescriptorFactory(
56-
SWIFT_LAUNCH_CONFIG_TYPE,
57-
new LLDBDebugAdapterExecutableFactory(toolchain, outputChannel)
58-
);
59-
60-
const debugConfigProvider = vscode.debug.registerDebugConfigurationProvider(
55+
return vscode.debug.registerDebugConfigurationProvider(
6156
SWIFT_LAUNCH_CONFIG_TYPE,
6257
new LLDBDebugConfigurationProvider(process.platform, toolchain, outputChannel)
6358
);
64-
65-
return {
66-
dispose: () => {
67-
debugConfigProvider.dispose();
68-
debugAdpaterFactory.dispose();
69-
},
70-
};
71-
}
72-
73-
/**
74-
* A factory class for creating and providing the executable descriptor for the LLDB Debug Adapter.
75-
* This class implements the vscode.DebugAdapterDescriptorFactory interface and is responsible for
76-
* determining the path to the LLDB Debug Adapter executable and ensuring it exists before launching
77-
* a debug session.
78-
*
79-
* This class uses the workspace context to:
80-
* - Resolve the path to the debug adapter executable.
81-
* - Verify that the debug adapter exists in the toolchain.
82-
*
83-
* The main method of this class, `createDebugAdapterDescriptor`, is invoked by VS Code to supply
84-
* the debug adapter executable when a debug session is started. The executable parameter by default
85-
* will be provided in package.json > contributes > debuggers > program if defined, but since we will
86-
* determine the executable via the toolchain anyway, this is now redundant and will be ignored.
87-
*
88-
* @implements {vscode.DebugAdapterDescriptorFactory}
89-
*/
90-
export class LLDBDebugAdapterExecutableFactory implements vscode.DebugAdapterDescriptorFactory {
91-
private toolchain: SwiftToolchain;
92-
private outputChannel: SwiftOutputChannel;
93-
94-
constructor(toolchain: SwiftToolchain, outputChannel: SwiftOutputChannel) {
95-
this.toolchain = toolchain;
96-
this.outputChannel = outputChannel;
97-
}
98-
99-
async createDebugAdapterDescriptor(): Promise<vscode.DebugAdapterDescriptor> {
100-
const path = await DebugAdapter.getLLDBDebugAdapterPath(this.toolchain);
101-
return new vscode.DebugAdapterExecutable(path, [], {});
102-
}
10359
}
10460

10561
/** Provide configurations for lldb-vscode/lldb-dap
@@ -150,6 +106,7 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
150106
);
151107
return undefined;
152108
}
109+
launchConfig.debugAdapterExecutable = lldbDapPath;
153110
}
154111

155112
return launchConfig;

test/unit-tests/debugger/debugAdapterFactory.test.ts

+6-38
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
import * as vscode from "vscode";
1616
import { expect } from "chai";
17-
import {
18-
LLDBDebugAdapterExecutableFactory,
19-
LLDBDebugConfigurationProvider,
20-
} from "../../../src/debugger/debugAdapterFactory";
17+
import { LLDBDebugConfigurationProvider } from "../../../src/debugger/debugAdapterFactory";
2118
import { Version } from "../../../src/utilities/version";
2219
import {
2320
mockGlobalObject,
@@ -28,46 +25,14 @@ import {
2825
mockFn,
2926
} from "../../MockUtils";
3027
import * as mockFS from "mock-fs";
31-
import {
32-
DebugAdapter,
33-
LaunchConfigType,
34-
SWIFT_LAUNCH_CONFIG_TYPE,
35-
} from "../../../src/debugger/debugAdapter";
28+
import { LaunchConfigType, SWIFT_LAUNCH_CONFIG_TYPE } from "../../../src/debugger/debugAdapter";
3629
import * as lldb from "../../../src/debugger/lldb";
3730
import { SwiftToolchain } from "../../../src/toolchain/toolchain";
3831
import { SwiftOutputChannel } from "../../../src/ui/SwiftOutputChannel";
3932
import * as debugAdapter from "../../../src/debugger/debugAdapter";
4033
import { Result } from "../../../src/utilities/result";
4134
import configuration from "../../../src/configuration";
4235

43-
suite("LLDBDebugAdapterExecutableFactory Tests", () => {
44-
const mockDebugAdapter = mockGlobalModule(DebugAdapter);
45-
let mockToolchain: MockedObject<SwiftToolchain>;
46-
let mockOutputChannel: MockedObject<SwiftOutputChannel>;
47-
48-
setup(() => {
49-
mockToolchain = mockObject<SwiftToolchain>({});
50-
mockOutputChannel = mockObject<SwiftOutputChannel>({
51-
log: mockFn(),
52-
});
53-
});
54-
55-
test("should return a DebugAdapterExecutable with the path to lldb-dap", async () => {
56-
const toolchainPath = "/path/to/debug/adapter";
57-
58-
mockDebugAdapter.getLLDBDebugAdapterPath.resolves(toolchainPath);
59-
60-
const factory = new LLDBDebugAdapterExecutableFactory(
61-
instance(mockToolchain),
62-
instance(mockOutputChannel)
63-
);
64-
const result = await factory.createDebugAdapterDescriptor();
65-
66-
expect(result).to.be.instanceOf(vscode.DebugAdapterExecutable);
67-
expect(result).to.have.property("command").that.equals(toolchainPath);
68-
});
69-
});
70-
7136
suite("LLDBDebugConfigurationProvider Tests", () => {
7237
let mockToolchain: MockedObject<SwiftToolchain>;
7338
let mockOutputChannel: MockedObject<SwiftOutputChannel>;
@@ -188,7 +153,10 @@ suite("LLDBDebugConfigurationProvider Tests", () => {
188153
request: "launch",
189154
program: "${workspaceFolder}/.build/debug/executable",
190155
});
191-
expect(launchConfig).to.containSubset({ type: LaunchConfigType.LLDB_DAP });
156+
expect(launchConfig).to.containSubset({
157+
type: LaunchConfigType.LLDB_DAP,
158+
debugAdapterExecutable: "/path/to/lldb-dap",
159+
});
192160
});
193161

194162
test("fails if the path to lldb-dap could not be found", async () => {

0 commit comments

Comments
 (0)