Skip to content

Commit 66b9283

Browse files
authored
[lldb] [debugserver] Shut down the exception thread when clearing (#70979)
MachProcess has a MachTask as an ivar. In the MachProcess dtor, we call MachTask::Clear() to clear its state, before running the dtor of all our ivars, including the MachTask one. When we attach on darwin, MachProcess calls MachTask::StartExceptionThread which does the task_for_pid and then starts a thread to listen for mach messages. Then MachProcess calls ptrace(PT_ATTACHEXC). If that ptrace() fails, MachProcess will call MachTask::Clear. But the exception thread is now up & running and is not stopped; its ivars will be reset by the Clear() method, and its object will be freed after the dtor runs. Actually eliciting a crash in this scenario is very timing sensitive; I hand-modified debugserver to fail to PT_ATTACHEXC trying to simulate it on my desktop and was unable. But looking at the source, and an occasional crash report we've received, it's clear that this is possible. rdar://117521198
1 parent ec350ad commit 66b9283

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lldb/tools/debugserver/source/MacOSX/MachTask.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@
145145
//----------------------------------------------------------------------
146146
void MachTask::Clear() {
147147
// Do any cleanup needed for this task
148+
if (m_exception_thread)
149+
ShutDownExcecptionThread();
148150
m_task = TASK_NULL;
149151
m_exception_thread = 0;
150152
m_exception_port = MACH_PORT_NULL;

0 commit comments

Comments
 (0)