Friday, February 15, 2008

How to trace function enter and exit


class FuncEnterExitTracer{
private:
LPCWSTR m_functionName;
public:
FuncEnterExitTracer(LPCWSTR functionName)
: m_functionName(functionName) {
TRACE(L"Entering: %s\n...", m_functionName);
}

~FuncEnterExitTracer() {
TRACE(L"Exiting: %s\n...", m_functionName);
}
};

#define TRACE_FUNC_ENTER_EXIT() FuncEnterExitTracer autoVariable (TEXT(__FUNCTION__))




Now in any function, you can use TRACE_FUNC_ENTER_EXIT(); to trace enter and exit:

void AnyFunc(int p1, ...)

{

TRACE_FUNC_ENTER_EXIT();

....................

}

No comments: