During one of my recent discussions with my manager, he mentioned that one of his former clients used a C++ macro to log info about every line of code. All they had to do was enable an environment variable before starting the run. (Of course the environment variable was enabled in the test-bed alone.
The log mentioned the variables used and their corresponding values too. For example, for the line:
a = a + b;
The log would say something like:
"a = a + b; (a = 5 + 3)"
Personally, I was not sure if this was possible, but he was very sure of this having existed, though he did not remember the specifics of the code.
So, here is the (obvious) question: Is this possible? Can you provide the code for this one?
You may check how BOOST_CHECKA from Boost.Test is implemented. Internally it uses expression templates.
For test:
Output is:
Note values in square brackets: [0+1!=2]
It has some limitations.
For test:
output is:
I don't know if every line/variable can be expanded like that, but function calls can be logged. I have logged all function calls using the
-finstrument-functions
option of gcc. It will call:and
for function enter and exit.
The docs explain how to use it. I don't know if other compilers offer something similar.