diff options
| author | bors <bors@rust-lang.org> | 2024-10-18 11:38:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-10-18 11:38:01 +0000 |
| commit | 4fc517264ecbc3198a197cda85cfa2ba4269047d (patch) | |
| tree | 84ffd7f1072d1d23a4f00b2c468e6e48f495df60 | |
| parent | 03cfa8e23444d0ccb97a0f697095a487cf5261c2 (diff) | |
| parent | 325d48fe7a9fe70c533f7bbc9553afd0cc0a465e (diff) | |
| download | rust-4fc517264ecbc3198a197cda85cfa2ba4269047d.tar.gz rust-4fc517264ecbc3198a197cda85cfa2ba4269047d.zip | |
Auto merge of #18320 - davidbarsky:davidbarsky/fix-lldb-dap-calling-rustc, r=Veykril
internal: fix lldb-dap unconditionally calling rustc Fixes https://github.com/rust-lang/rust-analyzer/issues/18318. I also took the opportunity to refactor how `discoverSourceFileMap` worked—it now returns a type instead of mutating a map in place. I tested this change using the LLDB DAP extension. I needed to set `"lldb-dap.executable-path": "/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-dap"` for everything to work, however, but once I did, was able to successfully debug a test.
| -rw-r--r-- | src/tools/rust-analyzer/editors/code/src/debug.ts | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/tools/rust-analyzer/editors/code/src/debug.ts b/src/tools/rust-analyzer/editors/code/src/debug.ts index 77ab44f24ce..9e2e3d2185b 100644 --- a/src/tools/rust-analyzer/editors/code/src/debug.ts +++ b/src/tools/rust-analyzer/editors/code/src/debug.ts @@ -6,7 +6,6 @@ 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"; @@ -152,9 +151,24 @@ async function getDebugConfiguration( const env = prepareEnv(inheritEnv, runnable.label, runnableArgs, config.runnablesExtraEnv); const executable = await getDebugExecutable(runnableArgs, env); let sourceFileMap = debugOptions.sourceFileMap; + if (sourceFileMap === "auto") { sourceFileMap = {}; - await discoverSourceFileMap(sourceFileMap, env, wsFolder); + const computedSourceFileMap = await discoverSourceFileMap(env, wsFolder); + + if (computedSourceFileMap) { + // lldb-dap requires passing the source map as an array of two element arrays. + // the two element array contains a source and destination pathname. + // TODO: remove lldb-dap-specific post-processing once + // https://github.com/llvm/llvm-project/pull/106919/ is released in the extension. + if (provider.type === "lldb-dap") { + provider.additional["sourceMap"] = [ + [computedSourceFileMap?.source, computedSourceFileMap?.destination], + ]; + } else { + sourceFileMap[computedSourceFileMap.source] = computedSourceFileMap.destination; + } + } } const debugConfig = getDebugConfig( @@ -189,11 +203,15 @@ async function getDebugConfiguration( return debugConfig; } +type SourceFileMap = { + source: string; + destination: string; +}; + async function discoverSourceFileMap( - sourceFileMap: Record<string, string>, env: Record<string, string>, cwd: string, -) { +): Promise<SourceFileMap | undefined> { const sysroot = env["RUSTC_TOOLCHAIN"]; if (sysroot) { // let's try to use the default toolchain @@ -203,9 +221,11 @@ async function discoverSourceFileMap( const commitHash = rx.exec(data)?.[1]; if (commitHash) { const rustlib = path.normalize(sysroot + "/lib/rustlib/src/rust"); - sourceFileMap[`/rustc/${commitHash}/`] = rustlib; + return { source: rustlib, destination: rustlib }; } } + + return; } type PropertyFetcher<Config, Input, Key extends keyof Config> = ( @@ -218,7 +238,7 @@ type DebugConfigProvider<Type extends string, DebugConfig extends BaseDebugConfi runnableArgsProperty: PropertyFetcher<DebugConfig, ra.CargoRunnableArgs, keyof DebugConfig>; sourceFileMapProperty?: keyof DebugConfig; type: Type; - additional?: Record<string, unknown>; + additional: Record<string, unknown>; }; type KnownEnginesType = (typeof knownEngines)[keyof typeof knownEngines]; @@ -236,16 +256,7 @@ const knownEngines: { "args", runnableArgs.executableArgs, ], - additional: { - sourceMap: [ - [ - `/rustc/${/commit-hash:\s(.*)$/m.exec( - execSync("rustc -V -v", {}).toString(), - )?.[1]}/library`, - "${config:rust-analyzer.cargo.sysroot}/lib/rustlib/src/rust/library", - ], - ], - }, + additional: {}, }, "vadimcn.vscode-lldb": { type: "lldb", |
