My contribution to Eclipse CDT: external-tool-based code checkers

by Алекс Руис on February 24, 2012

I’m very proud that my contribution, infrastructure for creating external-tool-based code checkers, is in the Eclipse CDT code repository!


(Adapted from my EclipseCon Europe 2011 session)

Eclipse CDT 8.0, part of the Indigo release, includes a nice code checking framework: Codan. Out of the box, Codan provides both the infrastructure needed to perform code checks and some useful, ready-to-use checkers.

Even though the provided checkers are a great addition to a developer’s toolbox, many more are needed for Codan to have feature parity with existing tools like Cppcheck. In addition, Codan’s infrastructure provides good support for writing AST-based checkers, but support for integrating external tools was missing.


The main reason for integrating Codan with external tools is to enjoy all the code checks from mature tools without leaving our beloved Eclipse. With the new infrastructure:

  • External tools can be configured using Codan’s preference page
  • External tools are invoked automatically when a C/C++ file is saved
  • The output of these tools can be displayed as editor markers

Example: Cppcheck

My contribution includes a Cppchecker-based checker. This checker is disabled by default but it can be easily enabled and configured in the Codan preference page. Before Juno release, we decided to move CppcheckChecker to the “examples” project.

(Click to enlarge)

A more detailed configuration dialog can be found by pressing the “Customize Selected…” button:

(Click to enlarge)

As you can see from the screenshot above, you can specify the path of the Cppcheck executable, the arguments to pass and whether Cppcheck’s output should be displayed in the console.

Now, let’s see it in action!

Writing your own external-tool-based checker

The new infrastructure makes it very easy to write your own external-tool-based checker. In the simplest case, you will need to:

  1. Extend the abstract class AbstractCxxExternalToolBasedChecker.
  2. Provide the name of your tool (e.g. “Cppcheck”.)
  3. Provide default values for the path of the executable, arguments to pass and whether the output of the tool should be displayed in the console.
  4. Provide one or more implementations of AbstractOutputParser. They will parse the output of the external tool, line by line. It’s up to you to decide what to do with the output (e.g. create error markers.)

You can take a look at the CppcheckChecker class here.

In the case of tools that are complex to set up, the new infrastructure is extremely flexible and configurable. It allows you to pretty much to configure every single aspect of the checker, from the files that the tool can check to the way to feed arguments to the tool.

Special thanks

Many, many thanks to my teammate and mentor, Sergey Prigogin, for his guidance and for reviewing and improving this work.

Sergey is one of the best engineers I have ever met in my career (in fact, he is in my top-3 list,) a nice gentleman, and the toughest code reviewer…ever. His attention to detail and his high standards for quality are just out of this world.

{ 5 comments… read them below or add one }

Michi June 10, 2012 at 2:29 am

Hi Alex,

I have CDT nightly snapshots installed, but I can’t find an artifact that contains the cppchecker example. Do you know whether and where cppchecker is packaged?

thx Michi


Alex Ruiz July 2, 2012 at 10:09 pm
Mathias July 9, 2012 at 3:07 am

I fear I must be missing something, but I cannot find the cppchecker checks anywhere either. I do see them in the code, but it would be nice to be able to select them in the Codan preferences (in other words: to be able to actually use them).


Alex Ruiz July 9, 2012 at 2:03 pm

Hello Mathias,

During EclipseCon CDT committers and I had a chat about CppcheckChecker and we agreed it should go to the “examples” project instead of Codan itself. The reason is that it should serve only as an example of how to write this type of checkers, since none of us is really a Cppcheck user, we could have missed some usability detail.

I’m sorry for not updating this blog post. I’ll do it as soon as I submit this comment :)


Sanda January 22, 2013 at 1:36 pm

Hi Alex,

is it possible to use custom code checkers in Eclipse Indigo anyhow?



Leave a Comment

{ 2 trackbacks }

Previous post:

Next post: