I want to log every function call and parameter value in my C++ app. Is there a generic approach for this task ? (3rd part library, VAR_ARGS etc.)
When running on Solaris, freeBSD, MacOS or another system where DTrace is available you can trace all function calls of any programm in this easy manner:
to trace a complete program run or
to attach to a program with it's pid.
One might also do a quick statistic on which functions are called how often:
There is also an option to automatically indent the code
and then a ton more of options to filter to get the info you actually need, as getting a log of all functions is a lot, even for a relatively simple program like
There is a special compiler flag in certain Microsoft compilers to call a "hook function" at the beginning of every function call for profiling purposes. The hook function can be used to do the logging you require.
This technique was used in the MockItNow project. However, I am not sure if MockItNow is still alive and usable.
You have not mentioned the platform your are using. For unix, similar techniques probably do exist.
Do a google search with parameters - "C/C++ built-in prprocessor macros". I know that the GNU and Microsoft provides some built-in macros. One I can remember and as a relevant reference is