I'm writing a profiler library whose task it is to print the names of the functions in an application as and when they are executed. To achieve this, I have compiled app with the /Gh flag and linked it to the profiler which has the definition of _penter. _penter calls a function that retrieves the name and prints it. This is happening correctly.
To remove instances where the same function is being printed twice, I'm using an unordered_set in the profiler.
This too works very well; except when the app includes the unordered_set class and uses it's methods.
When the app does this, the profiler's calls to unordered_set methods invoke _penter as well, thus putting the code into an infinite recursive loop, and causing a stackoverflow. I have made sure that the profiler is not built using the /Gh flag.
My guess is that the profiler and the app use the same copy of the standard library that contains unordered_set methods. But I do not know how to fix this.
I really need help in fixing this issue.
Thank you very much.
NOTE:
I think you need to make sure that /Gh option is provided per-file not for entire solution/project. When /Gh is provided to a certain compilation unit (i.e. .cpp file) it will instrument every single function in your file with _penter. Of course this applies to the headers with function definitions in this cpp file. Functions within std::unordered_set got instrumented because they are in a compilation unit which is instrumented. I would try with either precompiled header or somehow you need to move the definitions out of the files you instrument with /Gh.