Skip to content

Commit

Permalink
Add basic support for Native Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Feb 29, 2024
1 parent 0ac05c0 commit 8c6c0fe
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions editors/code/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ async function getDebugConfiguration(
if (!editor) return;

const knownEngines: Record<string, DebugConfigProvider> = {
"vadimcn.vscode-lldb": getLldbDebugConfig,
"ms-vscode.cpptools": getCppvsDebugConfig,
"ms-vscode.cpptools": getCCppDebugConfig,
"vadimcn.vscode-lldb": getCodeLldbDebugConfig,
"webfreak.debug": getNativeDebugConfig,
};
const debugOptions = ctx.config.debug;

Expand All @@ -97,12 +98,14 @@ async function getDebugConfiguration(
}

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

await vscode.window.showErrorMessage(
`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;
}
Expand Down Expand Up @@ -184,41 +187,62 @@ async function getDebugExecutableInfo(
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: "lldb",
type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg",
request: "launch",
name: runnable.label,
program: executable,
args: runnable.args.executableArgs,
cwd: cargoWorkspace || runnable.args.workspaceRoot,
sourceMap: sourceFileMap,
sourceLanguages: ["rust"],
sourceFileMap,
env,
};
}

function getCppvsDebugConfig(
function getCodeLldbDebugConfig(
runnable: ra.Runnable,
executable: string,
cargoWorkspace: string,
env: Record<string, string>,
sourceFileMap?: Record<string, string>,
): vscode.DebugConfiguration {
return {
type: os.platform() === "win32" ? "cppvsdbg" : "cppdbg",
type: "lldb",
request: "launch",
name: runnable.label,
program: executable,
args: runnable.args.executableArgs,
cwd: cargoWorkspace || runnable.args.workspaceRoot,
sourceFileMap,
sourceMap: sourceFileMap,
sourceLanguages: ["rust"],
env,
};
}

function getNativeDebugConfig(
runnable: ra.Runnable,
executable: string,
cargoWorkspace: string,
env: Record<string, string>,
_sourceFileMap?: Record<string, string>,
): vscode.DebugConfiguration {
return {
type: "gdb",
request: "launch",
name: runnable.label,
target: executable,
// FIXME: we emit an array here, but the extension expects a string
// See https://github.com/WebFreak001/code-debug/issues/359
arguments: runnable.args.executableArgs,
cwd: cargoWorkspace || runnable.args.workspaceRoot,
env,
valuesFormatting: "prettyPrinters",
};
}

0 comments on commit 8c6c0fe

Please sign in to comment.