You are here: Home / OSADL / News / 
2021-02-24 - 22:01
2011-08-21 12:00 Age: 10 Years

How to determine code coverage of a running program on the fly?

By: Carsten Emde

A new HOWTO at the OSADL Website knows more

Is your code covered?

It is well known that the gcov utility can be used to dump coverage data at the end of a program run - given that the program was compiled and linked with the related options. Sometimes, however, such data must be generated on the fly while the program is running. This may be the case in servers and, more generally, in devices that start a primary application when the device is switched on and its main function never stops unless the device is switched off. Embedded systems may come to mind.

Coverage data are needed for debugging and general testing and - more importantly - for specific testing in the case of a safety-critical application. Optimization can even go that far and feed coverage data back to the compiler using the -fbranch-probabilities option to further improve a program's performance.

Okay, but how does it work to obtain coverage data while the program is running? Well, we need to explicitly do what the program implicitly does when it exits. OSADL's Safety Coordinator Der Herr Hofrat analyzed how this works, created a small program to exemplify his solution and was kind enough to share his insight by providing an OSADL HOWTO article on this topic which is now online and accessible through the OSADL HOWTOs page.

Thank you, Nicholas.