python - Looking for a lightweight solution to systematically instrument the if-conditions of C functions -
i need use lightweight instrumentation tools (say, using existing python or maybe c pre-processor framework) systematically insert statements in if-conditions of c functions:
for example, let foo c function:
int foo(int x){ if (x>3) return x; }
i need transform
int foo(int x){ if (x>3){ print ("%d", x); return x; } }
i have tried using llvm, not integrate better other parts of code. here, prefer python/c preprocessor framework solution. ideas.
you consider using gcc melt or perhaps gcc python plugin customize gcc compiler transform gimple representation. complete solution, not sure qualifies "lightweight" (because need understand details of gcc internals), neither clang/llvm approach. you'll need more week of work (notably learn internals of gcc, or of clang/llvm)
btw, problem less easy believe, since
int foobar(int x) { return (x>3)?(x*6):(x*x); }
contains conditional. also, original function exactly equivalent to
int foo(int x){ while (x>3) // while done 0 or 1 time return x; }
and easy find many other ways express it.
so purely syntactic approach never work completely. hence, cannot hope "light".
(my opinion c code instrumentation never lightweight problem)
Comments
Post a Comment