Skip to content
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

[Testing] use llvm-pdbutil #130049

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions src/tools/run-make-support/src/external_deps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ pub struct LlvmDwarfdump {
cmd: Command,
}

/// A `llvm-dwarfdump` invocation builder.
#[derive(Debug)]
#[must_use]
pub struct LlvmPdbutil {
cmd: Command,
}

crate::macros::impl_common_helpers!(LlvmReadobj);
crate::macros::impl_common_helpers!(LlvmProfdata);
crate::macros::impl_common_helpers!(LlvmFilecheck);
Expand All @@ -118,6 +125,7 @@ crate::macros::impl_common_helpers!(LlvmAr);
crate::macros::impl_common_helpers!(LlvmNm);
crate::macros::impl_common_helpers!(LlvmBcanalyzer);
crate::macros::impl_common_helpers!(LlvmDwarfdump);
crate::macros::impl_common_helpers!(LlvmPdbutil);

/// Generate the path to the bin directory of LLVM.
#[must_use]
Expand Down Expand Up @@ -359,3 +367,19 @@ impl LlvmDwarfdump {
self
}
}

impl LlvmPdbutil {
/// Construct a new `llvm-pdbutil` invocation. This assumes that `llvm-pdbutil` is available
/// at `$LLVM_BIN_DIR/llvm-pdbutil`.
pub fn new() -> Self {
let llvm_pdbutil = llvm_bin_dir().join("llvm-pdbutil");
let cmd = Command::new(llvm_pdbutil);
Self { cmd }
}

/// Provide an input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
}
4 changes: 4 additions & 0 deletions tests/run-make/pdb-buildinfo-cl-cmd/filecheck.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CHECK: LF_BUILDINFO
CHECK: rustc.exe
CHECK: main.rs
CHECK: "-g" "--crate-name" "my_crate_name" "--crate-type" "bin" "-Cmetadata=dc9ef878b0a48666"
24 changes: 5 additions & 19 deletions tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//@ only-windows-msvc
// Reason: pdb files are unique to this architecture

use run_make_support::{assert_contains, bstr, env_var, rfs, rustc};
use run_make_support::{llvm, rustc};

fn main() {
rustc()
Expand All @@ -17,23 +17,9 @@ fn main() {
.crate_type("bin")
.metadata("dc9ef878b0a48666")
.run();
let tests = [
&env_var("RUSTC"),
r#""main.rs""#,
r#""-g""#,
r#""--crate-name""#,
r#""my_crate_name""#,
r#""--crate-type""#,
r#""bin""#,
r#""-Cmetadata=dc9ef878b0a48666""#,
];
for test in tests {
assert_pdb_contains(test);
}
}

fn assert_pdb_contains(needle: &str) {
let needle = needle.as_bytes();
use bstr::ByteSlice;
assert!(&rfs::read("my_crate_name.pdb").find(needle).is_some());
let pdbutil_result =
llvm::LlvmPdbutil::new().arg("dump").arg("-ids").input("my_crate_name.pdb").run();

llvm::llvm_filecheck().patterns("filecheck.txt").stdin(pdbutil_result.stdout_utf8()).run();
}
1 change: 1 addition & 0 deletions tests/run-make/pdb-sobjname/filecheck.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECK: S_OBJNAME{{.+}}my_great_crate_name{{.+}}.o
1 change: 1 addition & 0 deletions tests/run-make/pdb-sobjname/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
18 changes: 18 additions & 0 deletions tests/run-make/pdb-sobjname/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Check if the pdb file contains an S_OBJNAME entry with the name of the .o file

// This is because it used to be missing in #96475.
// See https://github.com/rust-lang/rust/pull/115704

//@ only-windows-msvc
// Reason: pdb files are unique to this architecture

use run_make_support::{llvm, rustc};

fn main() {
rustc().input("main.rs").arg("-g").crate_name("my_great_crate_name").crate_type("bin").run();

let pdbutil_result =
llvm::LlvmPdbutil::new().arg("dump").arg("-symbols").input("my_great_crate_name.pdb").run();

llvm::llvm_filecheck().patterns("filecheck.txt").stdin(pdbutil_result.stdout_utf8()).run();
}
Loading