Skip to content

Commit 9abfebd

Browse files
committed
Add an alternate --demangle mode to coverage-dump
The coverage-dump tool already needs `rustc_demangle` for its own purposes, so the amount of extra code needed for a demangle mode is very small.
1 parent bf8fff7 commit 9abfebd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/tools/coverage-dump/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ The output format is mostly arbitrary, so it's OK to change the output as long
66
as any affected tests are also re-blessed. However, the output should be
77
consistent across different executions on different platforms, so avoid
88
printing any information that is platform-specific or non-deterministic.
9+
10+
## Demangle mode
11+
12+
When run as `coverage-dump --demangle`, this tool instead functions as a
13+
command-line demangler that can be invoked by `llvm-cov`.

src/tools/coverage-dump/src/main.rs

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ fn main() -> anyhow::Result<()> {
77

88
let args = std::env::args().collect::<Vec<_>>();
99

10+
// The coverage-dump tool already needs `rustc_demangle` in order to read
11+
// coverage metadata, so it's very easy to also have a separate mode that
12+
// turns it into a command-line demangler for use by coverage-run tests.
13+
if &args[1..] == &["--demangle"] {
14+
return demangle();
15+
}
16+
1017
let llvm_ir_path = args.get(1).context("LLVM IR file not specified")?;
1118
let llvm_ir = std::fs::read_to_string(llvm_ir_path).context("couldn't read LLVM IR file")?;
1219

@@ -15,3 +22,15 @@ fn main() -> anyhow::Result<()> {
1522

1623
Ok(())
1724
}
25+
26+
fn demangle() -> anyhow::Result<()> {
27+
use std::fmt::Write as _;
28+
29+
let stdin = std::io::read_to_string(std::io::stdin())?;
30+
let mut output = String::with_capacity(stdin.len());
31+
for line in stdin.lines() {
32+
writeln!(output, "{:#}", rustc_demangle::demangle(line))?;
33+
}
34+
print!("{output}");
35+
Ok(())
36+
}

0 commit comments

Comments
 (0)