Skip to content

Commit 8e78be2

Browse files
add more checks and error messages
1 parent 8b42ee7 commit 8e78be2

File tree

3 files changed

+75
-49
lines changed

3 files changed

+75
-49
lines changed

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import * as util from "util";
33
import * as vscode from "vscode";
44
import * as child_process from "child_process";
55
import * as fs from "node:fs/promises";
6+
import {
7+
showErrorWithConfigureButton,
8+
showLLDBDapNotFoundMessage,
9+
} from "./ui/error-messages";
610

711
const exec = util.promisify(child_process.execFile);
812

@@ -91,12 +95,27 @@ async function getDAPExecutable(
9195
return undefined;
9296
}
9397

94-
function getDAPArguments(
98+
async function getDAPArguments(
9599
folder: vscode.WorkspaceFolder | undefined,
96100
configuration: vscode.DebugConfiguration,
97-
): string[] {
101+
userInteractive?: boolean,
102+
): Promise<string[] | null | undefined> {
98103
// Check the debug configuration for arguments first
99104
const debugConfigArgs = configuration.debugAdapterArgs;
105+
if (debugConfigArgs) {
106+
if (
107+
!Array.isArray(debugConfigArgs) ||
108+
debugConfigArgs.findIndex((entry) => typeof entry !== "string") !== -1
109+
) {
110+
if (!userInteractive) {
111+
return undefined;
112+
}
113+
return showErrorWithConfigureButton(
114+
"The debugAdapterArgs property must be an array of string values.",
115+
);
116+
}
117+
return debugConfigArgs;
118+
}
100119
if (
101120
Array.isArray(debugConfigArgs) &&
102121
debugConfigArgs.findIndex((entry) => typeof entry !== "string") === -1
@@ -109,29 +128,6 @@ function getDAPArguments(
109128
.get<string[]>("arguments", []);
110129
}
111130

112-
/**
113-
* Shows a modal when the debug adapter's path is not found
114-
*/
115-
async function showLLDBDapNotFoundMessage(path?: string) {
116-
const message =
117-
path !== undefined
118-
? `Debug adapter path: ${path} is not a valid file`
119-
: "Unable to find the path to the LLDB debug adapter executable.";
120-
const openSettingsAction = "Open Settings";
121-
const callbackValue = await vscode.window.showErrorMessage(
122-
message,
123-
{ modal: true },
124-
openSettingsAction,
125-
);
126-
127-
if (openSettingsAction === callbackValue) {
128-
vscode.commands.executeCommand(
129-
"workbench.action.openSettings",
130-
"lldb-dap.executable-path",
131-
);
132-
}
133-
}
134-
135131
/**
136132
* Creates a new {@link vscode.DebugAdapterExecutable} based on the provided workspace folder and
137133
* debug configuration. Assumes that the given debug configuration is for a local launch of lldb-dap.
@@ -176,7 +172,10 @@ export async function createDebugAdapterExecutable(
176172
...env,
177173
},
178174
};
179-
const dbgArgs = getDAPArguments(folder, configuration);
175+
const dbgArgs = await getDAPArguments(folder, configuration, userInteractive);
176+
if (!dbgArgs) {
177+
return undefined;
178+
}
180179

181180
return new vscode.DebugAdapterExecutable(dapPath, dbgArgs, dbgOptions);
182181
}

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,10 @@ import * as child_process from "child_process";
33
import * as util from "util";
44
import { LLDBDapServer } from "./lldb-dap-server";
55
import { createDebugAdapterExecutable } from "./debug-adapter-factory";
6+
import { showErrorWithConfigureButton } from "./ui/error-messages";
67

78
const exec = util.promisify(child_process.execFile);
89

9-
/**
10-
* Shows an error message to the user that optionally allows them to open their
11-
* launch.json to configure it.
12-
*
13-
* @param message The error message to display to the user
14-
* @returns `undefined` if the debug session should stop or `null` if the launch.json should be opened
15-
*/
16-
async function showErrorWithConfigureButton(
17-
message: string,
18-
): Promise<null | undefined> {
19-
const userSelection = await vscode.window.showErrorMessage(
20-
message,
21-
{ modal: true },
22-
"Configure",
23-
);
24-
25-
if (userSelection === "Configure") {
26-
return null; // Stops the debug session and opens the launch.json for editing
27-
}
28-
29-
return undefined; // Only stops the debug session
30-
}
31-
3210
/**
3311
* Determines whether or not the given lldb-dap executable supports executing
3412
* in server mode.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as vscode from "vscode";
2+
3+
/**
4+
* Shows a modal when the debug adapter's path is not found
5+
*/
6+
export async function showLLDBDapNotFoundMessage(path?: string) {
7+
const message =
8+
path !== undefined
9+
? `Debug adapter path: ${path} is not a valid file`
10+
: "Unable to find the path to the LLDB debug adapter executable.";
11+
const openSettingsAction = "Open Settings";
12+
const callbackValue = await vscode.window.showErrorMessage(
13+
message,
14+
{ modal: true },
15+
openSettingsAction,
16+
);
17+
18+
if (openSettingsAction === callbackValue) {
19+
vscode.commands.executeCommand(
20+
"workbench.action.openSettings",
21+
"lldb-dap.executable-path",
22+
);
23+
}
24+
}
25+
26+
/**
27+
* Shows an error message to the user that optionally allows them to open their
28+
* launch.json to configure it.
29+
*
30+
* Expected to be used in the context of a {@link vscode.DebugConfigurationProvider}.
31+
*
32+
* @param message The error message to display to the user
33+
* @returns `undefined` if the debug session should stop or `null` if the launch.json should be opened
34+
*/
35+
export async function showErrorWithConfigureButton(
36+
message: string,
37+
): Promise<null | undefined> {
38+
const userSelection = await vscode.window.showErrorMessage(
39+
message,
40+
{ modal: true },
41+
"Configure",
42+
);
43+
44+
if (userSelection === "Configure") {
45+
return null; // Stops the debug session and opens the launch.json for editing
46+
}
47+
48+
return undefined; // Only stops the debug session
49+
}

0 commit comments

Comments
 (0)