I would like to add some instructions to C/C++ programs from within clang without using an LLVM pass. I know it is possible but I can't find any documentation on how to do so.
As an example, given the program below
// before instrumentation
int main() {
int num = 0;
printf("%d\n", num);
}
I would like to be able to add arbitrary instructions from within clang and create a program like
// after instrumentation
int main() {
int num = 0;
if(num != 0) { // inserted code
// do stuff // inserted code
} // inserted code
printf("%d\n", num);
}
I found some projects that instrument code using clang (1, 2) but not any concrete documentation.