Skip to content

Commit 847dc6e

Browse files
committed
Make cargo aware of dwp files.
When using -Csplit-debuginfo=packed on Linux, rustc will produce a dwp file. Unlike the dwo files, whose paths are embedded into the binary, there's no information in the binary to help a debugger locate a dwp file. By convention, the dwp file for <EXE> is given the name <EXE>.dwp and placed next to <EXE>. When cargo hardlinks the executable file rustc put in target/debug/deps into target/debug, it also needs to hardlink the dwp file along with it. Failing to do this prevents the debugger from finding the dwp file when the binary is executed from target/debug, as there's no way for the debugger to know to look in the deps subdirectory.
1 parent 88f1429 commit 847dc6e

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

crates/cargo-test-support/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,17 @@ impl Execs {
831831
self
832832
}
833833

834+
pub fn enable_split_debuginfo_packed(&mut self) -> &mut Self {
835+
self.env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "packed")
836+
.env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "packed")
837+
.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed")
838+
.env("CARGO_PROFILE_BENCH_SPLIT_DEBUGINFO", "packed");
839+
self
840+
}
841+
834842
pub fn enable_mac_dsym(&mut self) -> &mut Self {
835843
if cfg!(target_os = "macos") {
836-
self.env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "packed")
837-
.env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "packed")
838-
.env("CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO", "packed")
839-
.env("CARGO_PROFILE_BENCH_SPLIT_DEBUGINFO", "packed");
844+
return self.enable_split_debuginfo_packed();
840845
}
841846
self
842847
}

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ impl TargetInfo {
462462
// preserved.
463463
should_replace_hyphens: true,
464464
})
465+
} else {
466+
ret.push(FileType {
467+
suffix: format!("{}.dwp", suffix),
468+
prefix: prefix.clone(),
469+
flavor: FileFlavor::DebugInfo,
470+
crate_type: Some(crate_type.clone()),
471+
should_replace_hyphens: crate_type != CrateType::Bin,
472+
})
465473
}
466474
}
467475

src/cargo/ops/cargo_clean.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
203203
rm_rf_glob(&split_debuginfo_obj, config, &mut progress)?;
204204
let split_debuginfo_dwo = dir_glob.join(format!("{}.*.dwo", crate_name));
205205
rm_rf_glob(&split_debuginfo_dwo, config, &mut progress)?;
206+
let split_debuginfo_dwp = dir_glob.join(format!("{}.*.dwp", crate_name));
207+
rm_rf_glob(&split_debuginfo_dwp, config, &mut progress)?;
206208

207209
// Remove the uplifted copy.
208210
if let Some(uplift_dir) = uplift_dir {

tests/testsuite/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5216,6 +5216,29 @@ fn uplift_pdb_of_bin_on_windows() {
52165216
assert!(!p.target_debug_dir().join("d.pdb").exists());
52175217
}
52185218

5219+
#[cargo_test]
5220+
#[cfg(target_os = "linux")]
5221+
fn uplift_dwp_of_bin_on_linux() {
5222+
let p = project()
5223+
.file("src/main.rs", "fn main() { panic!(); }")
5224+
.file("src/bin/b.rs", "fn main() { panic!(); }")
5225+
.file("src/bin/foo-bar.rs", "fn main() { panic!(); }")
5226+
.file("examples/c.rs", "fn main() { panic!(); }")
5227+
.file("tests/d.rs", "fn main() { panic!(); }")
5228+
.build();
5229+
5230+
p.cargo("build --bins --examples --tests")
5231+
.enable_split_debuginfo_packed()
5232+
.run();
5233+
assert!(p.target_debug_dir().join("foo.dwp").is_file());
5234+
assert!(p.target_debug_dir().join("b.dwp").is_file());
5235+
assert!(p.target_debug_dir().join("examples/c.dwp").exists());
5236+
assert!(p.target_debug_dir().join("foo-bar").is_file());
5237+
assert!(p.target_debug_dir().join("foo-bar.dwp").is_file());
5238+
assert!(!p.target_debug_dir().join("c.dwp").exists());
5239+
assert!(!p.target_debug_dir().join("d.dwp").exists());
5240+
}
5241+
52195242
// Ensure that `cargo build` chooses the correct profile for building
52205243
// targets based on filters (assuming `--profile` is not specified).
52215244
#[cargo_test]

0 commit comments

Comments
 (0)