Skip to content

Add support for LLDB-DAP #18265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions editors/code/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type * as ra from "./lsp_ext";
import { Cargo } from "./toolchain";
import type { Ctx } from "./ctx";
import { createTaskFromRunnable, prepareEnv } from "./run";
import { execSync } from "node:child_process";
import { execute, isCargoRunnableArgs, unwrapUndefinable } from "./util";
import type { Config } from "./config";

Expand Down Expand Up @@ -105,9 +106,11 @@ async function getDebugConfiguration(
const commandCCpp: string = createCommandLink("ms-vscode.cpptools");
const commandCodeLLDB: string = createCommandLink("vadimcn.vscode-lldb");
const commandNativeDebug: string = createCommandLink("webfreak.debug");
const commandLLDBDap: string = createCommandLink("llvm-vs-code-extensions.lldb-dap");

await vscode.window.showErrorMessage(
`Install [CodeLLDB](command:${commandCodeLLDB} "Open CodeLLDB")` +
`, [lldb-dap](command:${commandLLDBDap} "Open lldb-dap")` +
`, [C/C++](command:${commandCCpp} "Open C/C++") ` +
`or [Native Debug](command:${commandNativeDebug} "Open Native Debug") for debugging.`,
);
Expand Down Expand Up @@ -220,10 +223,30 @@ type DebugConfigProvider<Type extends string, DebugConfig extends BaseDebugConfi

type KnownEnginesType = (typeof knownEngines)[keyof typeof knownEngines];
const knownEngines: {
"llvm-vs-code-extensions.lldb-dap": DebugConfigProvider<"lldb-dap", LldbDapDebugConfig>;
"vadimcn.vscode-lldb": DebugConfigProvider<"lldb", CodeLldbDebugConfig>;
"ms-vscode.cpptools": DebugConfigProvider<"cppvsdbg" | "cppdbg", CCppDebugConfig>;
"webfreak.debug": DebugConfigProvider<"gdb", NativeDebugConfig>;
} = {
"llvm-vs-code-extensions.lldb-dap": {
type: "lldb-dap",
executableProperty: "program",
environmentProperty: (env) => ["env", Object.entries(env).map(([k, v]) => `${k}=${v}`)],
runnableArgsProperty: (runnableArgs: ra.CargoRunnableArgs) => [
"args",
runnableArgs.executableArgs,
],
additional: {
sourceMap: [
[
`/rustc/${/commit-hash:\s(.*)$/m.exec(
execSync("rustc -V -v", {}).toString(),
)?.[1]}/library`,
Comment on lines +242 to +244
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to avoid this regex + .exec call?

"${config:rust-analyzer.cargo.sysroot}/lib/rustlib/src/rust/library",
],
],
},
},
"vadimcn.vscode-lldb": {
type: "lldb",
executableProperty: "program",
Expand Down Expand Up @@ -336,6 +359,13 @@ type CCppDebugConfig = {
};
} & BaseDebugConfig<"cppvsdbg" | "cppdbg">;

type LldbDapDebugConfig = {
program: string;
args: string[];
env: string[];
sourceMap: [string, string][];
} & BaseDebugConfig<"lldb-dap">;

type CodeLldbDebugConfig = {
program: string;
args: string[];
Expand Down