很奇怪,我用 CreateProcess + DEBUG_ONLY_PROCESS选项,收不到被调试进程创建线程和退出线程的消息。
不知道各位谁遇到过,或是知道原因
int CMyDebugDoc::ThreadCreateDebugProcess(long lParam)
{
//进入调试循环
TCHAR szMessage[256];
TCHAR szTemp[256];
CMainFrame *pFrame=(CMainFrame *) AfxGetApp()->m_pMainWnd;
CMyDebugDoc *pSelf=(CMyDebugDoc*) lParam;
BOOL isContinue = TRUE;
DEBUG_EVENT stuDbgEvent = {0};
DWORD dwContinueStatus;
BOOL bRet;
STARTUPINFO StartupInfo;
PROCESS_INFORMATION pInfo;
LPVOID ptr = 0;
stuDllInfo* pDllInfo;
pSelf->ReleaseResource();
GetStartupInfo(&StartupInfo);
BOOL isCreateSucess = CreateProcess((LPCTSTR)pSelf->GetPathName(), NULL, NULL, NULL, TRUE,DEBUG_ONLY_THIS_PROCESS, NULL,NULL, &StartupInfo, &pInfo);
if (isCreateSucess == FALSE)
{
OutputDebugString(_T("建立调试进程失败!"));
return 1;
}
pSelf->m_hProcess=pInfo.hProcess;
while (isContinue)
{
dwContinueStatus = DBG_CONTINUE;
bRet = WaitForDebugEvent(&stuDbgEvent, INFINITE);
if (!bRet)
{
pFrame->m_wndOutput.m_wndOutputLog.AppendLog(_T("WaitForDebugEvent error!"));
return 1;
}
pSelf->m_stuDbgEvent = stuDbgEvent;
switch (stuDbgEvent.dwDebugEventCode)
{
case EXCEPTION_DEBUG_EVENT:
//处理异常
bRet = pSelf->OnDebugException();
if (bRet == FALSE)
{
dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
}
break;
case CREATE_THREAD_DEBUG_EVENT:
//创建线程
OutputDebugString(_T("新线程创建!"));
break;
case CREATE_PROCESS_DEBUG_EVENT:
OutputDebugString(_T("创建进程!"));
break;
case EXIT_THREAD_DEBUG_EVENT:
OutputDebugString(_T("有线程退出!"));
//退出线程
break;
case EXIT_PROCESS_DEBUG_EVENT:
OutputDebugString(_T("进程退出!"));
//退出进程
break;
case LOAD_DLL_DEBUG_EVENT:
OutputDebugString(_T("加载DLLpSelf));
break;
case UNLOAD_DLL_DEBUG_EVENT:
OutputDebugString(_T("UnLoadDLL")); //卸载DLL
break;
case OUTPUT_DEBUG_STRING_EVENT:
break;
}
bRet = ContinueDebugEvent(stuDbgEvent.dwProcessId,stuDbgEvent.dwThreadId, dwContinueStatus);
if (!bRet)
{
pSelf->OnOutputDebugString(&stuDbgEvent.u.DebugString,szMessage,512);
OutputDebugString(szMessage);
return 1;
}
}
OutputDebugString(_T("退出调试线程."));
return 0;
}
[注意]APP应用上架合规检测服务,协助应用顺利上架!