Skip to content

Commit 15c4e6b

Browse files
convert "pid" property in launch configuration to an integer (#1465)
1 parent cef4e6c commit 15c4e6b

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

src/debugger/debugAdapterFactory.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
8888
launchConfig.program += ".exe";
8989
}
9090

91+
// Convert "pid" property from a string to a number to make the process picker work.
92+
if ("pid" in launchConfig) {
93+
const pid = Number.parseInt(launchConfig.pid, 10);
94+
if (isNaN(pid)) {
95+
return await vscode.window
96+
.showErrorMessage(
97+
"Failed to launch debug session",
98+
{
99+
modal: true,
100+
detail: `Invalid process ID: "${launchConfig.pid}" is not a valid integer. Please update your launch configuration`,
101+
},
102+
"Configure"
103+
)
104+
.then(userSelection => {
105+
if (userSelection === "Configure") {
106+
return null; // Opens the launch configuration when returned from a DebugConfigurationProvider
107+
}
108+
return undefined; // Only stops the debug session from starting
109+
});
110+
}
111+
launchConfig.pid = pid;
112+
}
113+
91114
// Delegate to the appropriate debug adapter extension
92115
launchConfig.type = DebugAdapter.getLaunchConfigType(this.toolchain.swiftVersion);
93116
if (launchConfig.type === LaunchConfigType.CODE_LLDB) {

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,84 @@ suite("LLDBDebugConfigurationProvider Tests", () => {
4646
});
4747
});
4848

49+
test("allows specifying a 'pid' in the launch configuration", async () => {
50+
const configProvider = new LLDBDebugConfigurationProvider(
51+
"darwin",
52+
instance(mockToolchain),
53+
instance(mockOutputChannel)
54+
);
55+
const launchConfig = await configProvider.resolveDebugConfigurationWithSubstitutedVariables(
56+
undefined,
57+
{
58+
name: "Test Launch Config",
59+
type: SWIFT_LAUNCH_CONFIG_TYPE,
60+
request: "attach",
61+
pid: 41038,
62+
}
63+
);
64+
expect(launchConfig).to.containSubset({ pid: 41038 });
65+
});
66+
67+
test("converts 'pid' property from a string to a number", async () => {
68+
const configProvider = new LLDBDebugConfigurationProvider(
69+
"darwin",
70+
instance(mockToolchain),
71+
instance(mockOutputChannel)
72+
);
73+
const launchConfig = await configProvider.resolveDebugConfigurationWithSubstitutedVariables(
74+
undefined,
75+
{
76+
name: "Test Launch Config",
77+
type: SWIFT_LAUNCH_CONFIG_TYPE,
78+
request: "attach",
79+
pid: "41038",
80+
}
81+
);
82+
expect(launchConfig).to.containSubset({ pid: 41038 });
83+
});
84+
85+
test("shows an error when the 'pid' property is a string that isn't a number", async () => {
86+
// Simulate the user clicking the "Configure" button
87+
mockWindow.showErrorMessage.resolves("Configure" as any);
88+
89+
const configProvider = new LLDBDebugConfigurationProvider(
90+
"darwin",
91+
instance(mockToolchain),
92+
instance(mockOutputChannel)
93+
);
94+
const launchConfig = await configProvider.resolveDebugConfigurationWithSubstitutedVariables(
95+
undefined,
96+
{
97+
name: "Test Launch Config",
98+
type: SWIFT_LAUNCH_CONFIG_TYPE,
99+
request: "attach",
100+
pid: "not-a-number",
101+
}
102+
);
103+
expect(launchConfig).to.be.null;
104+
});
105+
106+
test("shows an error when the 'pid' property isn't a number or string", async () => {
107+
// Simulate the user clicking the "Configure" button
108+
mockWindow.showErrorMessage.resolves("Configure" as any);
109+
110+
const configProvider = new LLDBDebugConfigurationProvider(
111+
"darwin",
112+
instance(mockToolchain),
113+
instance(mockOutputChannel)
114+
);
115+
const launchConfig = await configProvider.resolveDebugConfigurationWithSubstitutedVariables(
116+
undefined,
117+
{
118+
name: "Test Launch Config",
119+
type: SWIFT_LAUNCH_CONFIG_TYPE,
120+
request: "attach",
121+
pid: {},
122+
}
123+
);
124+
expect(launchConfig).to.be.null;
125+
});
126+
49127
suite("CodeLLDB selected in settings", () => {
50128
let mockLldbConfiguration: MockedObject<vscode.WorkspaceConfiguration>;
51129
const mockLLDB = mockGlobalModule(lldb);

0 commit comments

Comments
 (0)