Search code examples
c++llvmcode-coveragellvm-cov

How do you use c++filt with llvm-cov report?


I'm trying to use a demangler with the llvm-cov report tool. The following is the command I'm running:

llvm-cov report /path/to/executable -instr-profile /path/to/default.profdata /path/to/src/ -Xdemangler c++filt -Xdemangler -n

I've tried rearranging the options and have tried using "-Xdemangler=c++filt -Xdemangler=-n" instead, and also using --no-strip-underscore instead of -n. It does not complain about the demangler, whereas if I make an obvious error with the command syntax it does tell me, but the output is not demangled.

From the llvm-cov documentation:

-Xdemangler=< TOOL >|< TOOL-OPTION > Specify a symbol demangler. This can be used to make reports more human-readable. This option can be specified multiple times to supply arguments to the demangler (e.g -Xdemangler c++filt -Xdemangler -n for C++). The demangler is expected to read a newline-separated list of symbols from stdin and write a newline-separated list of the same length to stdout.

I've used the following to ensure that c++filt works, and it does:

c++filt -n _ZN4core6ZipperC2ENSt3__110shared_ptrIN8core_gen14PlatformZipperEEE

Output:

core::Zipper::Zipper(std::__1::shared_ptr<core_gen::PlatformZipper>)

I have to use the -n option, or it will not demangle, but I'm at a loss for why llvm-cov does not seem to be using it correctly.

I've also tried using a shell script to try to capture the input llvm-cov gives to the demangler and write it to a file before invoking c++filt, but the file was empty when I looked after running the command.

Am I doing something wrong?


Solution

  • It appears use of demangled function names is not hooked in everywhere in llvm-cov.

    This report (the -name-regex option is needed to produce function names) does respond to the -Xdemangler option:

    llvm-cov report /path/to/exe -name-regex=\.* -instr-profile=default.profdata -Xdemangler=c++filt
    

    I see it's fixed in https://reviews.llvm.org/rL294136