The GNU tools include powerful utilities to collect coverage information. With coverage I know which lines of my code have been executed, which is a very useful test metric. The GNU coverage tools are commonly used for Linux applications. But to my surprise not much for embedded application development, mostly because it requires a few extra steps to have it available? Why not using free and powerful tools for improving software quality? This article explains how to install the GNU gcov tools into the Eclipse IDE.
Many Eclipse distributions come with the gcov integrated. In case your installed Eclipse does not have it installed, the following article describes how to install GNU Coverage tools (gcov) for it.
In this tutorial, I’m using the NXP MCUXpresso IDE 10.0.0 (build 344) as an example. This IDE is Eclipse Neon based and uses the ‘GNU Tools for ARM Embedded Processors 5 – Q3 2016’ release. The steps described should work for any other Eclipse or ARM tools version with minor changes.
To use the GNU gcov in Eclipse, I need the following parts:
- Eclipse gcov plugins installed
- gcov and related binutils
I wrote several articles about using gcov for embedded targets (see the links section at the end of this article). With newer Eclipse versions and GNU tools available, I decided to write an update.
1. Installation of Eclipse GCov Integration
💡 This step is only necessary if the Eclipse IDE does not have the plugins already installed.
Use the menu Help > Install New Software, and then point to the update site for your Eclipse version. For example the MCUXpresso IDE from NXP is Eclipse Neon based, so I’m using the following update site:
Under the Linux Tools group, select and install the GCov Integration.
This adds ‘Profiling’ settings, accessible with the menu Window > Preferences > C/C++ > Profiling:
With the plugin installed, I’m able to use the coverage information generated and I can open the coverage files from Eclipse:
Gcov plugin depends on several binutils (binary utilities) (such as gcov, addr2line, c++filt and nm).
💡 Make sure you are using matching binary utilities with your build system/compiler. Mixing binutils with different versions of other tools can have unpredictable side effects.
With my research I have found out that the following tools are required:
- gcov: GNU coverage tool, read coverage files and present the data
- addr2line: maps an application binary address to a source
- nm: lists symbols from a file
- c++filt: utility to deal with C++ name mangling
- strings: lists printable strings from files
- gprof: GNU profiling tool. Not needed for coverage. Listed for completeness or if you want to use profiling too.
On Windows I’m using the following batch file (update it to match your toolchain and IDE path):
# Batch file to check and copy the needed tools for gcov/gprof to be used in an Eclipse IDE # Example for using MCUXpresso IDE SET TOOLCHAIN_PATH=C:\nxp\MCUXpressoIDE_10.0.0_344\ide\tools\bin SET IDE=C:\nxp\MCUXpressoIDE_10.0.0_344\ide\mcuxpressoide.exe ECHO checking gcov/gprof dependencies on binutils IF NOT EXIST "%TOOLCHAIN_PATH%\gcov.exe" COPY "%TOOLCHAIN_PATH%\arm-none-eabi-gcov.exe" "%TOOLCHAIN_PATH%\gcov.exe" IF NOT EXIST "%TOOLCHAIN_PATH%\addr2line.exe" COPY "%TOOLCHAIN_PATH%\arm-none-eabi-addr2line.exe" "%TOOLCHAIN_PATH%\addr2line.exe" IF NOT EXIST "%TOOLCHAIN_PATH%\nm.exe" COPY "%TOOLCHAIN_PATH%\arm-none-eabi-nm.exe" "%TOOLCHAIN_PATH%\nm.exe" IF NOT EXIST "%TOOLCHAIN_PATH%\c++filt.exe" COPY "%TOOLCHAIN_PATH%\arm-none-eabi-c++filt.exe" "%TOOLCHAIN_PATH%\c++filt.exe" IF NOT EXIST "%TOOLCHAIN_PATH%\strings.exe" COPY "%TOOLCHAIN_PATH%\arm-none-eabi-strings.exe" "%TOOLCHAIN_PATH%\strings.exe" IF NOT EXIST "%TOOLCHAIN_PATH%\gprof.exe" COPY "%TOOLCHAIN_PATH%\arm-none-eabi-gprof.exe" "%TOOLCHAIN_PATH%\gprof.exe" ECHO Extending PATH SET PATH=%PATH%;%TOOLCHAIN_PATH% ECHO Launching Eclipse IDE "%IDE%"
It checks if the needed tools are present and copies them if needed.
It extends the system path to make sure they are found, and then launches the IDE with the new settings.
💡 I’m using that approach with a batch file as I don’t want to change the global system PATH variable (which would be a possibility).
Enabling gcov in Eclipse requires the plugins installed plus the matching gcov and binutils for the Eclipse IDE. For more detailed information how coverage works, see the links at the end of this article.
In a next article, I’m going to outline how to generate and collect coverage information in Eclipse.
Happy Covering 🙂
- GNU Coverage Tool: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html
- Code Coverage for Embedded Target with Eclipse, gcc and gcov: https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/
- Code Coverage with gcov, launchpad tools and Eclipse Kinetis Design Studio V3.0.0: https://mcuoneclipse.com/2015/05/31/code-coverage-with-gcov-launchpad-tools-and-eclipse-kinetis-design-studio-v3-0-0/
- Tutorial: Using GNU Profiling (gprof) with ARM Cortex-M: https://mcuoneclipse.com/2015/08/23/tutorial-using-gnu-profiling-gprof-with-arm-cortex-m/