[cfe-dev] source-to-source transformation to insert instrumentation calls
Dmitri Gribenko
gribozavr at gmail.com
Mon Sep 24 08:37:37 PDT 2012
On Sun, Sep 23, 2012 at 8:34 PM, Jan Smets <jan.smets at alcatel-lucent.com> wrote:
> Hi
>
> I'm trying to use CLANG to build a standalone source-to-source
> transformation tool. My first goal is to insert instrumentation calls for
> every memory access (wherever possible).
>
>
> For example, from this:
>
> int test(int *a)
> {
> int b;
> b = 0x10;
> *a = b;
>
> if(*a == 0x10)
> return 1;
> return 0;
> }
>
>
> To this:
>
> int test(int *a )
> {
> int b ;
>
> b = 0x10;
> instrument_write(*a, 4); // 4 is width
> *a = b;
>
> instrument_read(*a, 4);
> if (*a == 0x10) {
> return (1);
> }
> return (0);
> }
Hi Jan,
Just a note: I hope you understand that such source-level
instrumentation will not be precise. Optimizations eliminate memory
accesses. For example, in this case there will be only one store:
define i32 @test(i32* nocapture %a) nounwind {
store i32 16, i32* %a, align 4, !tbaa !0
ret i32 1
}
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-dev
mailing list