跟踪Visual Studio 2005 c ++多线程程序中函数的进入和退出的快速方法是什么? [英] What's a quick way to trace the entry and exit of functions in a Visual Studio 2005 c++ multithreaded program?
问题描述
由于我使用activemq-cpp API的方式,我的ActiveMQ库中出现间歇性崩溃。如果我能观察到导致崩溃的所有函数,则调试该问题会容易得多。有没有快速的方法来跟踪Visual Studio 2005 c ++多线程程序中函数的进入和退出?
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?
预先感谢!
推荐答案
使用Tracer对象。像这样的东西:
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_;
};
现在,您只需在函数顶部实例化Tracer对象,它将自动打印 exiting ...,当函数退出并调用析构函数时:
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");
...
}
这篇关于跟踪Visual Studio 2005 c ++多线程程序中函数的进入和退出的快速方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!