Skip to content

Commit 63b9636

Browse files
committed
Use pdb to read PDB symbols in fmt-write-bloat
As trying to read `main.exe` itself will yield no symbols.
1 parent 473757b commit 63b9636

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

tests/run-make/fmt-write-bloat/rmake.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
1818
//@ ignore-cross-compile
1919

20-
use run_make_support::artifact_names::bin_name;
2120
use run_make_support::env::no_debug_assertions;
22-
use run_make_support::rustc;
2321
use run_make_support::symbols::any_symbol_contains;
22+
use run_make_support::{bin_name, is_msvc, pdb, rustc, target};
2423

2524
fn main() {
2625
rustc().input("main.rs").opt().run();
@@ -31,8 +30,40 @@ fn main() {
3130
// otherwise, add them to the list of symbols to deny.
3231
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
3332
}
34-
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can trivially
35-
// satisfy the "no panic symbol" assertion.
36-
assert!(any_symbol_contains(bin_name("main"), &["main"]));
37-
assert!(!any_symbol_contains(bin_name("main"), &panic_syms));
33+
34+
if is_msvc() {
35+
use pdb::FallibleIterator;
36+
37+
let file = std::fs::File::open("main.pdb").expect("failed to open `main.pdb`");
38+
let mut pdb = pdb::PDB::open(file).expect("failed to parse `main.pdb`");
39+
40+
let symbol_table = pdb.global_symbols().expect("failed to parse PDB global symbols");
41+
let mut symbols = symbol_table.iter();
42+
43+
let mut found_symbols = vec![];
44+
45+
while let Some(symbol) = symbols.next().expect("failed to parse symbol") {
46+
match symbol.parse() {
47+
Ok(pdb::SymbolData::Public(data)) => {
48+
found_symbols.push(data.name.to_string());
49+
}
50+
_ => {}
51+
}
52+
}
53+
54+
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can
55+
// trivially satisfy the "no panic symbol" assertion.
56+
assert!(found_symbols.iter().any(|sym| sym == "main"), "expected `main` symbol");
57+
58+
for found_symbol in found_symbols {
59+
for panic_symbol in &panic_syms {
60+
assert_ne!(found_symbol, *panic_symbol, "found unexpected panic machinery symbol");
61+
}
62+
}
63+
} else {
64+
// Make sure we at least have the `main` symbol itself, otherwise even no symbols can
65+
// trivially satisfy the "no panic symbol" assertion.
66+
assert!(any_symbol_contains(bin_name("main"), &["main"]));
67+
assert!(!any_symbol_contains(bin_name("main"), &panic_syms));
68+
}
3869
}

0 commit comments

Comments
 (0)