<rdar://problem/14195566>

Found a race condition when killing an application where the state could be set to exited by the waitpid_thread() _before_ we call task resume (via MachProcess::PrivateResume()) in MachProcess::Kill().

llvm-svn: 185048
This commit is contained in:
Greg Clayton 2013-06-27 00:23:57 +00:00
parent 8edefb3665
commit 6467ff9aea
2 changed files with 13 additions and 9 deletions

View File

@ -132,7 +132,7 @@ waitpid_thread (void *arg)
while (1)
{
pid_t child_pid = waitpid(pid, &status, 0);
DNBLogThreadedIf(LOG_PROCESS, "waitpid_process_thread (): waitpid (pid = %i, &status, 0) => %i, status = %i, errno = %i", pid, child_pid, status, errno);
DNBLogThreadedIf(LOG_PROCESS, "waitpid_thread (): waitpid (pid = %i, &status, 0) => %i, status = %i, errno = %i", pid, child_pid, status, errno);
if (child_pid < 0)
{
@ -148,7 +148,7 @@ waitpid_thread (void *arg)
}
else// if (WIFEXITED(status) || WIFSIGNALED(status))
{
DNBLogThreadedIf(LOG_PROCESS, "waitpid_process_thread (): setting exit status for pid = %i to %i", child_pid, status);
DNBLogThreadedIf(LOG_PROCESS, "waitpid_thread (): setting exit status for pid = %i to %i", child_pid, status);
DNBProcessSetExitStatus (child_pid, status);
return NULL;
}
@ -157,7 +157,7 @@ waitpid_thread (void *arg)
// We should never exit as long as our child process is alive, so if we
// do something else went wrong and we should exit...
DNBLogThreadedIf(LOG_PROCESS, "waitpid_process_thread (): main loop exited, setting exit status to an invalid value (-1) for pid %i", pid);
DNBLogThreadedIf(LOG_PROCESS, "waitpid_thread (): main loop exited, setting exit status to an invalid value (-1) for pid %i", pid);
DNBProcessSetExitStatus (pid, -1);
return NULL;
}

View File

@ -268,23 +268,27 @@ MachProcess::SetState(nub_state_t new_state)
PTHREAD_MUTEX_LOCKER(locker, m_state_mutex);
const nub_state_t old_state = m_state;
if (old_state != new_state)
if (old_state == eStateExited)
{
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::SetState(%s) ignoring new state since current state is exited", DNBStateAsString(new_state));
}
else if (old_state == new_state)
{
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::SetState(%s) ignoring redundant state change...", DNBStateAsString(new_state));
}
else
{
if (NUB_STATE_IS_STOPPED(new_state))
event_mask = eEventProcessStoppedStateChanged;
else
event_mask = eEventProcessRunningStateChanged;
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::SetState ( old = %s, new = %s ) updating state, event_mask = 0x%8.8x", DNBStateAsString(old_state), DNBStateAsString(new_state), event_mask);
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::SetState(%s) upating state (previous state was %s), event_mask = 0x%8.8x", DNBStateAsString(new_state), DNBStateAsString(old_state), event_mask);
m_state = new_state;
if (new_state == eStateStopped)
m_stop_count++;
}
else
{
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::SetState ( old = %s, new = %s ) ignoring state...", DNBStateAsString(old_state), DNBStateAsString(new_state));
}
}
if (event_mask != 0)