Adding GNU Coverage Tools to Eclipse

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.

gcov with Embedded Target

gcov with Embedded Target

Outline

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:

  1. Eclipse gcov plugins installed
  2. 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:

http://download.eclipse.org/releases/neon

Under the Linux Tools group, select and install the GCov Integration.

GCov Integration Installation

GCov Integration Installation

This adds ‘Profiling’ settings, accessible with the menu Window > Preferences > C/C++ > Profiling:

Profiling Preferences

Profiling Preferences

With the plugin installed, I’m able to use the coverage information generated and I can open the coverage files from Eclipse:

Coverage Files

Coverage Files

2. Binutils

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.

coverage and related binutils

coverage and related binutils

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).

Summary

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 🙂

Links

Advertisements

4 thoughts on “Adding GNU Coverage Tools to Eclipse

  1. Pingback: GNU Code Coverage on Embedded Target with Eclipse Neon and ARM gcc 5 | MCU on Eclipse

  2. Hi Erich – rather than copying arm-none-eabi-addr2line.exe to addr2line.exe etc. can’t you just change the names/prefixes of the tools under Window > Preferences > C/C++ > Profiling > Binutils Preferences?

    You can probably even preconfigure these by putting the settings in a plugin_customization.ini file referenced by eclipse.ini:

    http://blog.vogella.com/2012/08/07/eclipse-papercut-9-default-preference-settings-via-plugin_customization-ini-type-filter-example/

    org.eclipse.linuxtools.binutils/PREFKEY_ADDR2LINE_CMD=arm-none-eabi-addr2line
    org.eclipse.linuxtools.binutils/PREFKEY_CPPFILT_CMD=arm-none-eabi-c++filt
    org.eclipse.linuxtools.binutils/PREFKEY_NM_CMD=arm-none-eabi-nm
    org.eclipse.linuxtools.binutils/PREFKEY_STRINGS_CMD=arm-none-eabi-strings

    Hope this helps.
    Regards
    Tommy

    Like

    • Hi Tommy,
      I considered changing the tool names in the Binutils preferences, but the problem is that this does not allow me to set the names for all the needed tools. So instead doing it in multiple places halfway, I decided to rename all of the tools. And that way it would not be a workspace setting which I would have to repeat for every workspace.

      Like

      • OK – I didn’t notice that not all of the relevant tools can be renamed in the GUI. That seems like a bit of an oversight in the Gcov configuration GUI. I understand now why you do it the way that you do. Thanks.

        Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s