1 //! Demangles rustc mangled names.
3 //! This tool uses https://crates.io/crates/rustc-demangle to convert an input buffer of
4 //! newline-separated mangled names into their demangled translations.
6 //! This tool can be leveraged by other applications that support third-party demanglers.
7 //! It takes a list of mangled names (one per line) on standard input, and prints a corresponding
8 //! list of demangled names. The tool is designed to support other programs that can leverage a
9 //! third-party demangler, such as `llvm-cov`, via the `-Xdemangler=<path-to-demangler>` option.
11 //! To use `rust-demangler`, first build the tool with:
14 //! $ ./x.py build rust-demangler
17 //! Then, with `llvm-cov` for example, add the `-Xdemangler=...` option:
20 //! $ TARGET="${PWD}/build/x86_64-unknown-linux-gnu"
21 //! $ "${TARGET}"/llvm/bin/llvm-cov show --Xdemangler="${TARGET}"/stage0-tools-bin/rust-demangler \
22 //! --instr-profile=main.profdata ./main --show-line-counts-or-regions
25 use rustc_demangle::demangle;
26 use std::io::{self, Read, Write};
28 fn main() -> io::Result<()> {
29 let mut buffer = String::new();
30 io::stdin().read_to_string(&mut buffer)?;
31 let lines = buffer.lines();
32 let mut demangled = Vec::new();
33 for mangled in lines {
34 demangled.push(demangle(mangled).to_string());
36 demangled.push("".to_string());
37 io::stdout().write_all(demangled.join("\n").as_bytes())?;