对注册表作如下设置:Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]"Auto"="1""Debugger"="\"C:\\WinDbg\\windbg.exe\" -p %ld -e %ld"UserDebuggerHotKey"=dword:00000000
之后有程序的Crash都可以Invoke Windbg来attach到这个程序,但是下面的这段程序的Crash(在程序中主动调用AfxThrowMemoryException或者throw std::exception("hello world"))没有导致WinDbg被调用且被附加:int foo(int x,inty){ AfxThrowMemoryException(); //throw std::exception("hello world"); return 1;}
程序中调用这个函数之后
WinDbg并没有被调用?请各位高手给个解释?Thanks in advance!
这是因为应用程序内部的运行库代码捕捉并处理了这个异常,没有执行到崩溃和JIT调试那一阶段。
如果是带有窗口的MFC程序,那么MFC库的默认窗口函数中有一个TRY{}CATCH(),用户代码没有处理的异常会被这个CATCH捕捉到,参考MFC源代码的WINCORE.CPP中的AfxCallWndProc函数:
LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg, WPARAM wParam = 0, LPARAM lParam = 0){
...
TRY {#ifndef _AFX_NO_OCC_SUPPORT // special case for WM_DESTROY if ((nMsg == WM_DESTROY) && (pWnd->m_pCtrlCont != NULL)) pWnd->m_pCtrlCont->OnUIActivate(NULL);#endif
// special case for WM_INITDIALOG CRect rectOld; DWORD dwStyle = 0; if (nMsg == WM_INITDIALOG) _AfxPreInitDialog(pWnd, &rectOld, &dwStyle);
// delegate to object's WindowProc lResult = pWnd->WindowProc(nMsg, wParam, lParam);
// more special case for WM_INITDIALOG if (nMsg == WM_INITDIALOG) _AfxPostInitDialog(pWnd, rectOld, dwStyle); } CATCH_ALL(e) { lResult = AfxGetThread()->ProcessWndProcException(e, &pThreadState->m_lastSentMsg); TRACE1("Warning: Uncaught exception in WindowProc (returning %ld).\n", lResult); DELETE_EXCEPTION(e); } END_CATCH_ALL