[cfe-dev] source-to-source transformation to insert instrumentation calls
Jan Smets
jan.smets at alcatel-lucent.com
Mon Sep 24 08:43:42 PDT 2012
On 24/09/2012 17:37, Dmitri Gribenko wrote:
> 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
>
That's OK. I'm aware that I won't be 100% accurate.
Now I just need to figure out a good location to insert the call! :)
Thanks for the feedback.
More information about the cfe-dev
mailing list