프로세스에 연결하고 크래시 덤프 파일을 작성하기 위해 작성한 디버깅 프로그램이 있습니다. 그 부분은 잘 작동합니다.DebugActiveProcessStop이 디버깅 응용 프로그램을 중단시키는 이유는 무엇입니까?
문제점은 디버거 프로그램이 종료 될 때 디버깅하는 프로그램도 마찬가지입니다.
Google 검색을 수행하고 DebugActiveProcessStop() API 호출을 발견했습니다. Windows XP에서만 소개 되었기 때문에 이전 MSDN 설명서에는이 파일이 표시되지 않았으므로 런타임에 Kernel32.dll에서 dynamicall을로드하려고 시도했습니다.
이제 제 문제는 _DebugActiveProcessStop() 호출이 수행되는 즉시 디버거 프로그램이 충돌한다는 것입니다. 누군가 내가 뭘 잘못하고 있는지 말해 줄 수 있니?
typedef BOOL (*DEBUGACTIVEPROCESSSTOP)(DWORD);
DEBUGACTIVEPROCESSSTOP _DebugActiveProcessStop;
HMODULE hK32 = LoadLibrary("kernel32.dll");
if(hK32)
_DebugActiveProcessStop = (DEBUGACTIVEPROCESSSTOP) GetProcAddress(hK32,"DebugActiveProcessStop");
else
{
printf("Can't load Kernel32.dll\n");
return;
}
if(! _DebugActiveProcessStop)
{
printf("Can't find DebugActiveProcessStop\n");
return;
}
...
void DebugLoop(void)
{
DEBUG_EVENT de;
while(1)
{
WaitForDebugEvent(&de, INFINITE);
switch(de.dwDebugEventCode)
{
case CREATE_PROCESS_DEBUG_EVENT:
hProcess = de.u.CreateProcessInfo.hProcess;
break;
case EXCEPTION_DEBUG_EVENT:
// PDS: I want a crash dump immediately!
dwProcessId = de.dwProcessId;
dwThreadId = de.dwThreadId;
WriteCrashDump(&de.u.Exception);
return;
case CREATE_THREAD_DEBUG_EVENT:
case OUTPUT_DEBUG_STRING_EVENT:
case EXIT_THREAD_DEBUG_EVENT:
case EXIT_PROCESS_DEBUG_EVENT :
case LOAD_DLL_DEBUG_EVENT:
case UNLOAD_DLL_DEBUG_EVENT:
case RIP_EVENT:
default:
break;
}
ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
}
}
...
void main(void)
{
...
BOOL bo = DebugActiveProcess(dwProcessId);
if(bo == 0)
printf("DebugActiveProcess failed, GetLastError: %u \n",GetLastError());
hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessId);
if(hProcess == NULL)
printf("OpenProcess failed, GetLastError: %u \n",GetLastError());
DebugLoop();
_DebugActiveProcessStop(dwProcessId);
CloseHandle(hProcess);
}