Skip to content

Commit a01e4f8

Browse files
committed
Add basic support for Native Debug
1 parent 0ac05c0 commit a01e4f8

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

Diff for: editors/code/src/debug.ts

+49-11
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ async function getDebugConfiguration(
8181
if (!editor) return;
8282

8383
const knownEngines: Record<string, DebugConfigProvider> = {
84-
"vadimcn.vscode-lldb": getLldbDebugConfig,
85-
"ms-vscode.cpptools": getCppvsDebugConfig,
84+
"ms-vscode.cpptools": getCCppDebugConfig,
85+
"vadimcn.vscode-lldb": getCodeLldbDebugConfig,
86+
"webfreak.debug": getNativeDebugConfig,
8687
};
8788
const debugOptions = ctx.config.debug;
8889

@@ -97,12 +98,14 @@ async function getDebugConfiguration(
9798
}
9899

99100
if (!debugEngine) {
101+
const commandCCpp: string = createCommandLink("ms-vscode.cpptools");
100102
const commandCodeLLDB: string = createCommandLink("vadimcn.vscode-lldb");
101-
const commandCpp: string = createCommandLink("ms-vscode.cpptools");
103+
const commandNativeDebug: string = createCommandLink("webfreak.debug");
102104

103105
await vscode.window.showErrorMessage(
104106
`Install [CodeLLDB](command:${commandCodeLLDB} "Open CodeLLDB")` +
105-
` or [C/C++](command:${commandCpp} "Open C/C++") extension for debugging.`,
107+
`, [C/C++](command:${commandCCpp} "Open C/C++") ` +
108+
`or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
106109
);
107110
return;
108111
}
@@ -184,41 +187,76 @@ async function getDebugExecutableInfo(
184187
return executableInfo;
185188
}
186189

187-
function getLldbDebugConfig(
190+
function getCCppDebugConfig(
188191
runnable: ra.Runnable,
189192
executable: string,
190193
cargoWorkspace: string,
191194
env: Record<string, string>,
192195
sourceFileMap?: Record<string, string>,
193196
): vscode.DebugConfiguration {
194197
return {
195-
type: "lldb",
198+
type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg",
196199
request: "launch",
197200
name: runnable.label,
198201
program: executable,
199202
args: runnable.args.executableArgs,
200203
cwd: cargoWorkspace || runnable.args.workspaceRoot,
201-
sourceMap: sourceFileMap,
202-
sourceLanguages: ["rust"],
204+
sourceFileMap,
203205
env,
204206
};
205207
}
206208

207-
function getCppvsDebugConfig(
209+
function getCodeLldbDebugConfig(
208210
runnable: ra.Runnable,
209211
executable: string,
210212
cargoWorkspace: string,
211213
env: Record<string, string>,
212214
sourceFileMap?: Record<string, string>,
213215
): vscode.DebugConfiguration {
214216
return {
215-
type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg",
217+
type: "lldb",
216218
request: "launch",
217219
name: runnable.label,
218220
program: executable,
219221
args: runnable.args.executableArgs,
220222
cwd: cargoWorkspace || runnable.args.workspaceRoot,
221-
sourceFileMap,
223+
sourceMap: sourceFileMap,
224+
sourceLanguages: ["rust"],
222225
env,
223226
};
224227
}
228+
229+
function getNativeDebugConfig(
230+
runnable: ra.Runnable,
231+
executable: string,
232+
cargoWorkspace: string,
233+
env: Record<string, string>,
234+
_sourceFileMap?: Record<string, string>,
235+
): vscode.DebugConfiguration {
236+
return {
237+
type: "gdb",
238+
request: "launch",
239+
name: runnable.label,
240+
target: executable,
241+
// See https://github.com/WebFreak001/code-debug/issues/359
242+
arguments: quote(runnable.args.executableArgs),
243+
cwd: cargoWorkspace || runnable.args.workspaceRoot,
244+
env,
245+
valuesFormatting: "prettyPrinters",
246+
};
247+
}
248+
249+
// Based on https://github.com/ljharb/shell-quote/blob/main/quote.js
250+
function quote(xs: string[]) {
251+
return xs
252+
.map(function (s) {
253+
if (/["\s]/.test(s) && !/'/.test(s)) {
254+
return "'" + s.replace(/(['\\])/g, "\\$1") + "'";
255+
}
256+
if (/["'\s]/.test(s)) {
257+
return '"' + s.replace(/(["\\$`!])/g, "\\$1") + '"';
258+
}
259+
return s.replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, "$1\\$2");
260+
})
261+
.join(" ");
262+
}

0 commit comments

Comments
 (0)