Tips and Tricks

Consider the following tips and tricks to get the code coverage you expect.

Simple Code

When performing code coverage on a simple program in main(), do not let the program simply end. Depending on the device, the code could reset or end up in an undefined state. This may interfere with code coverage calculation. It is suggested that you place something like a while(1) loop at the end of main(). Then to see code coverage, either:

  • Place a breakpoint at the last brace of the while(1) loop. When you hit the breakpoint, step once to ensure you have completed the loop to see the coverage output.
  • Let the code run for a while before hitting Pause. This will ensure that the while(1) loop was run (and covered) at least once. View coverage output.

Optimized Code

Different optimizations (-On) may result in different coverage of code. The code may be optimized so that it becomes smaller, faster, or more efficient in its operation. A code that is optimized for size will produce different coverage results from code that is optimized for speed.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.