Skip to content

Commit 39fe35a

Browse files
author
the_janitor
committed
Fixed a bug in which thread termination froze
1 parent bbab635 commit 39fe35a

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

TitanEngine/TitanEngine.Debugger.DebugLoop.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,30 @@ __declspec(dllexport) void TITCALL DebugLoop()
109109
}
110110
}
111111

112-
if (IsDbgReplyLaterSupported && DBGEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
112+
if (IsDbgReplyLaterSupported)
113113
{
114-
// Check if there is a thread processing a single step
115-
if (ThreadBeingProcessed != 0 && DBGEvent.dwThreadId != ThreadBeingProcessed)
114+
if (DBGEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
116115
{
117-
// Reply to the dbg event later
118-
DBGCode = DBG_REPLY_LATER;
116+
// Check if there is a thread processing a single step
117+
if (ThreadBeingProcessed != 0 && DBGEvent.dwThreadId != ThreadBeingProcessed)
118+
{
119+
// Reply to the dbg event later
120+
DBGCode = DBG_REPLY_LATER;
121+
122+
goto continue_dbg_event;
123+
}
124+
}
125+
else if (DBGEvent.dwDebugEventCode == EXIT_THREAD_DEBUG_EVENT)
126+
{
127+
if (ThreadBeingProcessed != 0 && DBGEvent.dwThreadId == ThreadBeingProcessed)
128+
{
129+
// Resume the other threads since the thread being processed is exiting
130+
for (auto& Thread : SuspendedThreads)
131+
ResumeThread(Thread.hThread);
119132

120-
goto continue_dbg_event;
133+
SuspendedThreads.clear();
134+
ThreadBeingProcessed = 0;
135+
}
121136
}
122137
}
123138

@@ -1394,7 +1409,7 @@ __declspec(dllexport) void TITCALL DebugLoop()
13941409
break;
13951410
}
13961411

1397-
if (IsDbgReplyLaterSupported)
1412+
if (IsDbgReplyLaterSupported && DBGEvent.dwDebugEventCode != EXIT_THREAD_DEBUG_EVENT)
13981413
{
13991414
CONTEXT DbgCtx;
14001415

@@ -1414,6 +1429,11 @@ __declspec(dllexport) void TITCALL DebugLoop()
14141429
if (ThreadBeingProcessed == Thread.dwThreadId)
14151430
continue;
14161431

1432+
// Check if the thread is already suspended
1433+
for (auto& SuspendedThread : SuspendedThreads)
1434+
if (SuspendedThread.dwThreadId == Thread.dwThreadId)
1435+
continue;
1436+
14171437
if (SuspendThread(Thread.hThread) != -1)
14181438
SuspendedThreads.push_back(Thread);
14191439
}

0 commit comments

Comments
 (0)