Matt Rajca

LLVM, Code Coverage and Xcode 4

August 14, 2011

As of Xcode 4.3, the Clang frontend can generate code coverage reports using the same flags that were supported by GCC.

Simply open your target’s Build Settings pane in Xcode, and set the “Instrument Program Flow” and “Generate Test Coverage Files” settings to ‘Yes’. Now if you build and run your target, Xcode will output gcda and gcov files to a well-hidden path inside its DerivedData directory. To find it, right click on your target in Xcode’s Products group, and select ‘Show in Finder’. Navigate up the path hierarchy to the Build folder.

Now open up the Intermediates/$TARGET.build/$CONFIG/$TARGET.build/Objects-normal/$ARCH subfolder. Inside, you’ll find the aforementioned gcda and gcov files. Since Clang outputs these files in the same format as GCC, they are compatible with tools such as Xcoverage, my OS X code coverage visualizer.