Reputation: 167
I would like to write a program that does automatic instrumentation of an input C/C++ code based on some input properties. I am seeking a good place to start learning how to do so (mainly related on how to do instrumentation, where to do so, etc.). I have been searching online for a while without any good luck. So I appreciate if someone can help me by pointing me to a good place to start from.
Thank you
Upvotes: 4
Views: 10214
Reputation: 38932
In case you haven't found it yet, here is very similar question with great ideas to use custom LLVM Pass and GCC MELT: Instrumenting C/C++ code using LLVM
If you are looking for something simpler, check this preprocessor-based solution for Basic Instrumentation and Profiling Framework for C++
Upvotes: 3
Reputation: 6776
If you are on Linux, and you just want system API calls, take a look at strace, or read this question.
If you want to instrument your own code, things get trickier. Profilers do this all the time, but they work with the compiler to add the instrumentation. It appears that gcc supports some form of this for user-defined instrumentation. See this question.
I find that rarely do I need the whole program instrumented--usually just a few critical areas need it. In this case, defining some instrumentation macros or adding some #ifdef MY_TRACE ... #endif
sections helps.
Upvotes: 2