Code instrumentation in Clang?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Code instrumentation in Clang?

Robert Ankeney
This post was updated on .
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 guessing 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!

Note: After some further investigation, I just discovered libclang which
looks like it could be my best friend. I just found the excellent Apple
developers meeting video on libclang.  Coupled with a rewriter, I might just
have what I need.   Any pointers to good examples of using libclang and/or
a rewriter would be great.

Thanks!
Robert
_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Code instrumentation in Clang?

Kostya Serebryany
Why would you want to add instrumentation in Clang and not in LLVM? 
For an example of LLVM instrumentation pass, take a look at lib/Transforms/Instrumentation/AddressSanitizer.cpp. 

--kcc 

On Sat, Jan 21, 2012 at 8:13 AM, Robert Ankeney <[hidden email]> wrote:
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!

Thanks!
Robert
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Code instrumentation in Clang?

Robert Ankeney
I would like to instrument the C/C++ source so that it can be compiled
under most any compiler, not just Clang.  The only way I see to do
that would be either through libclang or maybe with a recursive AST
visitor.  I was hoping to find a good example to work from, assuming I
need a Rewriter.  If there's something I'm missing, feel free to
correct me!

Thanks,
Robert

On Mon, Jan 23, 2012 at 9:58 AM, Kostya Serebryany [via Clang
Developers] <[hidden email]> wrote:

> Why would you want to add instrumentation in Clang and not in LLVM?
> For an example of LLVM instrumentation pass, take a look
> at lib/Transforms/Instrumentation/AddressSanitizer.cpp.
>
> --kcc
>
> On Sat, Jan 21, 2012 at 8:13 AM, Robert Ankeney <[hidden email]> wrote:
>>
>> 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!
>>
>> Thanks!
>> Robert
>> _______________________________________________
>> cfe-dev mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://clang-developers.42468.n3.nabble.com/Code-instrumentation-in-Clang-tp3678010p3682517.html
> To unsubscribe from Code instrumentation in Clang?, click here.
> NAML
Reply | Threaded
Open this post in threaded view
|

Re: Code instrumentation in Clang?

Stephen Kelly
In reply to this post by Robert Ankeney
Robert Ankeney wrote:

> 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!
>

TestCocoon does exactly that:

http://www.testcocoon.org/

Thanks,

Steve.


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Code instrumentation in Clang?

Robert Ankeney
Thanks for the pointer.  TestCocoon looks promising, though I'm
looking at performing Modified Condition/Decision Coverage (MC/DC) and
perhaps perform some metrics.  In any case, I was looking at doing
something to get more involved in Clang.  I'll have a look at
TestCocoon and maybe I can contribute there too.

Robert

On Sun, Jan 29, 2012 at 1:28 PM, Stephen Kelly [via Clang Developers]
<[hidden email]> wrote:

> Robert Ankeney wrote:
>
>> 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!
>>
>
> TestCocoon does exactly that:
>
> http://www.testcocoon.org/
>
> Thanks,
>
> Steve.
>
>
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://clang-developers.42468.n3.nabble.com/Code-instrumentation-in-Clang-tp3678010p3698305.html
> To unsubscribe from Code instrumentation in Clang?, click here.
> NAML
Reply | Threaded
Open this post in threaded view
|

Re: Code instrumentation in Clang?

gr.rosu
TestCocoon page now is replaced by http://www.froglogic.com/squish/coco/
But it seems a commencial tool. No source code.