Add basic support for Native Debug

This commit is contained in:
Laurențiu Nicola 2024-02-29 16:00:29 +02:00
parent 0ac05c0527
commit a01e4f8b72

View file

@ -81,8 +81,9 @@ async function getDebugConfiguration(
if (!editor) return; if (!editor) return;
const knownEngines: Record<string, DebugConfigProvider> = { const knownEngines: Record<string, DebugConfigProvider> = {
"vadimcn.vscode-lldb": getLldbDebugConfig, "ms-vscode.cpptools": getCCppDebugConfig,
"ms-vscode.cpptools": getCppvsDebugConfig, "vadimcn.vscode-lldb": getCodeLldbDebugConfig,
"webfreak.debug": getNativeDebugConfig,
}; };
const debugOptions = ctx.config.debug; const debugOptions = ctx.config.debug;
@ -97,12 +98,14 @@ async function getDebugConfiguration(
} }
if (!debugEngine) { if (!debugEngine) {
const commandCCpp: string = createCommandLink("ms-vscode.cpptools");
const commandCodeLLDB: string = createCommandLink("vadimcn.vscode-lldb"); const commandCodeLLDB: string = createCommandLink("vadimcn.vscode-lldb");
const commandCpp: string = createCommandLink("ms-vscode.cpptools"); const commandNativeDebug: string = createCommandLink("webfreak.debug");
await vscode.window.showErrorMessage( await vscode.window.showErrorMessage(
`Install [CodeLLDB](command:${commandCodeLLDB} "Open CodeLLDB")` + `Install [CodeLLDB](command:${commandCodeLLDB} "Open CodeLLDB")` +
` or [C/C++](command:${commandCpp} "Open C/C++") extension for debugging.`, `, [C/C++](command:${commandCCpp} "Open C/C++") ` +
`or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
); );
return; return;
} }
@ -184,7 +187,26 @@ async function getDebugExecutableInfo(
return executableInfo; return executableInfo;
} }
function getLldbDebugConfig( function getCCppDebugConfig(
runnable: ra.Runnable,
executable: string,
cargoWorkspace: string,
env: Record<string, string>,
sourceFileMap?: Record<string, string>,
): vscode.DebugConfiguration {
return {
type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg",
request: "launch",
name: runnable.label,
program: executable,
args: runnable.args.executableArgs,
cwd: cargoWorkspace || runnable.args.workspaceRoot,
sourceFileMap,
env,
};
}
function getCodeLldbDebugConfig(
runnable: ra.Runnable, runnable: ra.Runnable,
executable: string, executable: string,
cargoWorkspace: string, cargoWorkspace: string,
@ -204,21 +226,37 @@ function getLldbDebugConfig(
}; };
} }
function getCppvsDebugConfig( function getNativeDebugConfig(
runnable: ra.Runnable, runnable: ra.Runnable,
executable: string, executable: string,
cargoWorkspace: string, cargoWorkspace: string,
env: Record<string, string>, env: Record<string, string>,
sourceFileMap?: Record<string, string>, _sourceFileMap?: Record<string, string>,
): vscode.DebugConfiguration { ): vscode.DebugConfiguration {
return { return {
type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg", type: "gdb",
request: "launch", request: "launch",
name: runnable.label, name: runnable.label,
program: executable, target: executable,
args: runnable.args.executableArgs, // See https://github.com/WebFreak001/code-debug/issues/359
arguments: quote(runnable.args.executableArgs),
cwd: cargoWorkspace || runnable.args.workspaceRoot, cwd: cargoWorkspace || runnable.args.workspaceRoot,
sourceFileMap,
env, env,
valuesFormatting: "prettyPrinters",
}; };
} }
// Based on https://github.com/ljharb/shell-quote/blob/main/quote.js
function quote(xs: string[]) {
return xs
.map(function (s) {
if (/["\s]/.test(s) && !/'/.test(s)) {
return "'" + s.replace(/(['\\])/g, "\\$1") + "'";
}
if (/["'\s]/.test(s)) {
return '"' + s.replace(/(["\\$`!])/g, "\\$1") + '"';
}
return s.replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, "$1\\$2");
})
.join(" ");
}