Improve detaching

This commit is contained in:
Duncan Ogilvie 2020-10-10 17:50:15 +02:00
parent 821234ae37
commit ddfa81366e
2 changed files with 26 additions and 2 deletions

View File

@ -28,8 +28,31 @@ namespace GleeBug
{ {
//wait for a debug event //wait for a debug event
mIsRunning = true; mIsRunning = true;
if (!MyWaitForDebugEvent(&mDebugEvent, INFINITE)) if (!MyWaitForDebugEvent(&mDebugEvent, 100))
break; {
if (mDetach)
{
if (!UnsafeDetach())
cbInternalError("Debugger::Detach failed!");
break;
}
#if 0
// Fix based on work by https://github.com/number201724
if (WaitForSingleObject(mMainProcess.hProcess, 0) == WAIT_OBJECT_0)
{
mDebugEvent.dwDebugEventCode = EXIT_PROCESS_DEBUG_EVENT;
mDebugEvent.dwProcessId = mMainProcess.dwProcessId;
mDebugEvent.dwThreadId = mMainProcess.dwThreadId;
if (!GetExitCodeProcess(mMainProcess.hProcess, &mDebugEvent.u.ExitProcess.dwExitCode))
mDebugEvent.u.ExitProcess.dwExitCode = 0xFFFFFFFF;
}
#endif
else
{
// Regular timeout, wait again
continue;
}
}
mIsRunning = false; mIsRunning = false;
//set default continue status //set default continue status

View File

@ -74,6 +74,7 @@ namespace GleeBug
bool Debugger::UnsafeDetach() bool Debugger::UnsafeDetach()
{ {
// TODO: remove from all threads?
Registers(mThread->hThread, CONTEXT_CONTROL).TrapFlag = false; Registers(mThread->hThread, CONTEXT_CONTROL).TrapFlag = false;
return !!DebugActiveProcessStop(mMainProcess.dwProcessId); return !!DebugActiveProcessStop(mMainProcess.dwProcessId);
} }