Not sure if feasible… I am reading a large software code, and sometimes feel lost when tracing how certain variable is accessed.
It would be great if there is tool/method to trace that.
More specifically, suppose I have the following class.
class A
{
public:
int _a;
};
...
and whenever
... = ...->_a;
during runtime, I would like to print out FILE and LINE. Thank you for the suggestion.
P.S., I could grep all “->_a” appearances, but that is also pretty hard to sort out.
Instead of:
You could do something like this:
Following your example:
Create a class and provide an operator for implicit conversion;
Substitute your member variable for this new class.
The implicit conversion operator will do the work.
It will print:
A tip: never let a member variable be public. Always provide an accessor method.
Edit
Sorry, I forgot about FILE and LINE:
I didn’t find a way to inject LINE or FILE because the implicit cast will be done at runtime while macro substitution under preprocessing.
What you can do it is to put a breakpoint at implicit conversion function, as pointed by @veer, and manually trace each calling.
Edit 2
At least it is possible to see the call stack at runtime.
On Linux this can be done through execinfo and on Windows through StackWalker.