[cfe-dev] Code instrumentation in Clang?

Robert Ankeney rrankene at gmail.com
Sat Jan 21 08:13:39 PST 2012

I'm trying to get up to speed on using Clang by doing a bit of dynamic
code analysis by instrumenting C (and maybe C++) code where I take a
source file and generate an instrumented output. I'd like to add a
function call at the beginning of any block to mark statement coverage
and also change all boolean expressions to call some function so I can
track that too. For example:
	foo = a && (b || c);
would become something like:
	foo = EXPR_AND(a, EXPR_OR(b, c));
and thus I can track all combinations of conditions that occur.  I'd
need to track where in the source code I am too, and save that info
seperately.  This is a bit beyond what gcov provides.
I'm gussing that using a RecursiveASTVisitor would be the best
approach, but whatever approach I take, is there an easy way to output
the C code for each node I visit?
Any suggestions of what to look at to accomplish something like this
would be most appreciated!


More information about the cfe-dev mailing list