You can use the -finstrument-functions program option of Clang to instrument each and every function call in a way to execute code before and after the body of the functions.
With finstrument-functions you will not be able to replace funtions, the original function will always be called. Note that there is a prototype implementation to make it possible to replace functions (that feature might be really handy in testing legacy code) : https://github.com/martong/finstrument_mock
I am not sure what is the exact nature of the problem you want to solve, but perhaps the compiler is not the best tool to do such instrumentation. Generally the technique you want is called Function/Method Call Interception (FCI/MCI). One very good dynamic instrumentation tool is the debugger itself. For static binary instrumentation you could use e.g. Intel PIN. There is a great article about available FCI methods here: http://onlinelibrary.wiley.com/doi/10.1002/spe.2501/abstract
On Fri, Jun 23, 2017 at 5:50 AM, yonggang_chen via cfe-dev <[hidden email]> wrote:
I have a large project which consists of several millions of C++ code. Now I want to add a log function to each line of code. If do it manually, it’s almost impossible.