Code coverage on clang

Hi,
I know how to use GCOV and LCOV to get code coverage on GCC.
But This time i need to use clang and get instrumented binaries and code
coverage.

Please help (not able to find much info yet). Tried using -fprofile-arcs and
-ftest-coverage. code is compiling fine but giving link errors.

Thanks in Advance,
Kalpesh

The profiling library in gcc is called "libgcov", but clang has its own
named "libprofile_rt" and you need to link against that. The --coverage
flag implies -lprofile_rt when linking, or you can pass -lprofile_rt
yourself.

The code for libprofile_rt is part of compiler-rt:
http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/profile/ . If you
don't have libprofile_rt, you'll need to build it.

Nick

Note that the default coverage information format is for llvm-cov. If
you want to use gcov for some reason, you'll need to specify the
options "-Xclang -coverage-cfg-checksum -Xclang
-coverage-no-function-names-in-data -Xclang -coverage-version='407*'"
(see 16568 – There should be an user-friendly option for selecting coverage file flavour.).

Best Regards
Magnus Reftel

gcov doesn't have a single fixed format. If you're using the gcov from
gcc-4.7 then yes you use those flags mentioned. The default that clang
emits should be gcc-4.2 compatible, which is supposed to work with llvm-cov
or with a gcov binary from gcc 4.2

Nick

Thanks for the help.
using libprofile_rt, the code is compiling and linking now and I am getting
.so but no .gcno file is there. is that needed or am I missing something?

The .gcno is emitted at compile time (the -ftest-coverage flag) while the
.gcda is emitted when the instrumented program runs. You'll need both files.

Sorry, May be I am asking dumb question, I am very very new to clang and C++
world:
1. we are creating an android app and to build ndk c++ part, we are using
clang as our compiler. We are using windows for our OS choice, will it cause
additional problems?
2. We got *.gcno, it was generating in temp folder (not with shared lib :
*.so)
   a. compile flags used: -fprofile-arcs -ftest-coverage
   b. link flags used: -lprofile_rt -lgcc
3. where do I get llvm-cov. which binaries should I download from
LLVM Download Page. As suggested we are using windows as
our build machine. Do we need to switch to ubuntu?
4. How to get html report for codecoverage(as lcov does for gcc). will
llvm-cov would help there?

Let me phrase questions in simple words:
1. I need llvm-cov.exe to generate code coverage reports (using generated
*.gcno & *.gcda).
2. I tried using one present in
clang+llvm-3.2-x86-mingw32-EXPERIMENTAL\bin\llvm-cov.exe (downloaded from
LLVM Download Page). but it is not working, giving error
- "pthreadGC2.dll is missing"

Thanks,
Kalpesh