Code coverage for _constructor()/_destructor()'s?

Ian Lance Taylor iant@google.com
Thu Jul 1 06:58:00 GMT 2010


Jay Vaughan <jay.vaughan@thalesgroup.com> writes:

> Are there methods of using GNU coverage which will allow me to save my
> coverage information for the cases where death is warranted by my
> guardian library?  Is there some way for me to manually force coverage
> to be written prior to doing my big exit() call in the constructor?
> Has anyone else run into this problem and solved it?

The coverage code runs a constructor at the default initialization
priority.  Since your code is running at a higher priority, it runs
before coverage has been initialized.

Ideally you could call __gcov_init (info) at the start of your
constructor.  The problem is that __gcov_init takes an argument, a
pointer to a struct gcov_info, and you should really pass the same
pointer as the default constructor will pass.  But there is no way for
your code to get that value.

I can't think of anything that would work without changing and
rebuilding the compiler and the gcov support code.

Ian



More information about the Gcc-help mailing list