Skip to content

Commit b423842

Browse files
convert pid to a number so that lldb-dap can properly consume it
1 parent b9083ea commit b423842

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

lldb/tools/lldb-dap/src-ts/commands/pick-process.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ interface ProcessQuickPick extends vscode.QuickPickItem {
99
/**
1010
* Prompts the user to select a running process.
1111
*
12+
* The return value must be a string so that it is compatible with VS Code's
13+
* string substitution infrastructure. The value will eventually be converted
14+
* to a number by the debug configuration provider.
15+
*
1216
* @returns The pid of the process as a string or undefined if cancelled.
1317
*/
1418
export async function pickProcess(): Promise<string | undefined> {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as vscode from "vscode";
2+
3+
/**
4+
* Converts the given value to an integer if it isn't already.
5+
*
6+
* If the value cannot be converted then this function will return undefined.
7+
*
8+
* @param value the value to to be converted
9+
* @returns the integer value or undefined if unable to convert
10+
*/
11+
function convertToInteger(value: any): number | undefined {
12+
let result: number | undefined;
13+
switch (typeof value) {
14+
case "number":
15+
result = value;
16+
break;
17+
case "string":
18+
result = Number(value);
19+
break;
20+
default:
21+
return undefined;
22+
}
23+
if (!Number.isInteger(result)) {
24+
return undefined;
25+
}
26+
return result;
27+
}
28+
29+
/**
30+
* A {@link vscode.DebugConfigurationProvider} used to resolve LLDB DAP debug configurations.
31+
*
32+
* Performs checks on the debug configuration before launching a debug session.
33+
*/
34+
export class LLDBDapConfigurationProvider
35+
implements vscode.DebugConfigurationProvider
36+
{
37+
resolveDebugConfigurationWithSubstitutedVariables(
38+
_folder: vscode.WorkspaceFolder | undefined,
39+
debugConfiguration: vscode.DebugConfiguration,
40+
): vscode.ProviderResult<vscode.DebugConfiguration> {
41+
// Convert the "pid" option to a number if it is a string
42+
if ("pid" in debugConfiguration) {
43+
const pid = convertToInteger(debugConfiguration.pid);
44+
if (pid === undefined) {
45+
vscode.window.showErrorMessage(
46+
"Invalid debug configuration: property 'pid' must either be an integer or a string containing an integer value.",
47+
);
48+
return null;
49+
}
50+
debugConfiguration.pid = pid;
51+
}
52+
return debugConfiguration;
53+
}
54+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
isExecutable,
77
} from "./debug-adapter-factory";
88
import { DisposableContext } from "./disposable-context";
9+
import { LLDBDapConfigurationProvider } from "./debug-configuration-provider";
910

1011
/**
1112
* This class represents the extension and manages its life cycle. Other extensions
@@ -14,6 +15,12 @@ import { DisposableContext } from "./disposable-context";
1415
export class LLDBDapExtension extends DisposableContext {
1516
constructor() {
1617
super();
18+
this.pushSubscription(
19+
vscode.debug.registerDebugConfigurationProvider(
20+
"lldb-dap",
21+
new LLDBDapConfigurationProvider(),
22+
),
23+
);
1724
this.pushSubscription(
1825
vscode.debug.registerDebugAdapterDescriptorFactory(
1926
"lldb-dap",

0 commit comments

Comments
 (0)