Xcode 7 code coverage littering project directory with GCDA files

1

I'm running my unit tests in Xcode 7 for the first time, after refactoring my Swift code for 2.0 and fixing all of the various new compiler warnings and errors. I'm seeing a few different behaviors, though, which are probably all related.

  1. As the unit tests conclude, I get a gcda file for each system framework I link against dumped into my project root directory (e.g. QuartzCore.gcda, CoreData.gcda)
  2. I get a long list of the following errors:

    < project root >/CoreGraphics.gcda: cannot merge previous GCDA file: corrupt arc tag (0x00000017)

  3. Finally, I get an EXC_BAD_ACCESS exception thrown, with this stack trace:

    #0  0x0000000105cf06b4 in llvm_gcda_emit_function ()
    #1  0x0000000105845c0a in __llvm_gcov_writeout ()
    #2  0x0000000105cf18e4 in llvm_writeout_files ()
    #3  0x00007fff9641271b in __cxa_finalize_ranges ()
    #4  0x00007fff96412a30 in exit ()
    #5  0x0000000100056e9f in ___XCTestMain_block_invoke ()
    #6  0x000000010000e7c9 in -[XCTestDriver _runSuite] ()
    #7  0x000000010000f31a in -[XCTestDriver _checkForTestManager] ()
    #8  0x0000000100056c69 in _XCTestMain ()
    #9  0x0000000100001dc9 in ___lldb_unnamed_function3$$xctest ()
    #10 0x00007fff9098d5c9 in start ()
    #11 0x00007fff9098d5c9 in start ()
    

I have Enable Code Coverage Support and Generate Legacy Test Coverage Files turned on, though I've tried toggling the latter and it made no difference. I'm using Xcode 7.1 on OS X 10.10.5.

Turning on Gather coverage data for the scheme appeared to fix #3, but then it came back.

objective-c
xcode
macos
code-coverage
xcode7
asked on Stack Overflow Oct 30, 2015 by Dov • edited Nov 2, 2015 by Dov

1 Answer

0

In Xcode 7.1.1, it might be a bug of __gcov_flush(). I hook it and fix it as follow:

  1. In the file that calls __gcov_flush(), replace the extern void __gcov_flush(void); with #import “GCDAProfiling.h”.

  2. Then drag this file to your Xcode project: GCDAProfiling.c, GCDAProfiling.h, InstrProfilingUtil.c, InstrProfilingUtil.h from https://github.com/liuslevis/GCDACorruptionFix

  3. build and run.

I add function skip_special_file() and adding overflow protection to file GCDAProfiling.c. Xcode does not crash anymore, and the counting of line of code recovered by command lgcov from .gcda file seems to be non-zero.

Ref.: http://davidlau.me/2015/12/05/Trying-to-fix-Xcode-7-GDCA-file-corruption/

answered on Stack Overflow Apr 20, 2016 by David X. Lau • edited Apr 22, 2016 by David X. Lau

User contributions licensed under CC BY-SA 3.0