Search code examples
c++visual-studio-2005traceactivemq-classicvisual-c++-2005

What's a quick way to trace the entry and exit of functions in a Visual Studio 2005 c++ multithreaded program?


I have intermittent crashes occurring in my ActiveMQ libraries due to the way I'm using the activemq-cpp API. It'd be much easier to debug the issue if I could observe every function being called leading up to the crash. Are there any quick ways to trace the entry and exit of functions in a Visual Studio 2005 c++ multithreaded program?

Thanks in advance!


Solution

  • Use a Tracer object. Something like this:

    
    class Tracer
    {
    public:
      Tracer(const char *functionName) : functionName_(functionName)
      {
        cout << "Entering function " << functionName_ << endl;
      }
    
      ~Tracer()
      {
        cout << "Exiting function " << functionName_ << endl;
      }
    
      const char *functionName_;
    };
    

    Now you can simply instantiate a Tracer object at the top the function, and it will automatically print "exiting... " when the function exits and the destructor is called:

    
    void foo()
    {
      Tracer t("foo");
       ...
    }