Fixing a problem where CommandObjectThreadContinue held the thread list lock while waiting for the process to stop after a continue.

llvm-svn: 190626
This commit is contained in:
Andrew Kaylor 2013-09-12 19:15:05 +00:00
parent e5416ec2d2
commit 9063bf462a
1 changed files with 18 additions and 9 deletions

View File

@ -660,11 +660,14 @@ public:
StateType state = process->GetState(); StateType state = process->GetState();
if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended)) if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended))
{ {
Mutex::Locker locker (process->GetThreadList().GetMutex());
const uint32_t num_threads = process->GetThreadList().GetSize();
const size_t argc = command.GetArgumentCount(); const size_t argc = command.GetArgumentCount();
if (argc > 0) if (argc > 0)
{ {
// These two lines appear at the beginning of both blocks in
// this if..else, but that is because we need to release the
// lock before calling process->Resume below.
Mutex::Locker locker (process->GetThreadList().GetMutex());
const uint32_t num_threads = process->GetThreadList().GetSize();
std::vector<Thread *> resume_threads; std::vector<Thread *> resume_threads;
for (uint32_t i=0; i<argc; ++i) for (uint32_t i=0; i<argc; ++i)
{ {
@ -674,7 +677,7 @@ public:
if (success) if (success)
{ {
Thread *thread = process->GetThreadList().FindThreadByIndexID(thread_idx).get(); Thread *thread = process->GetThreadList().FindThreadByIndexID(thread_idx).get();
if (thread) if (thread)
{ {
resume_threads.push_back(thread); resume_threads.push_back(thread);
@ -693,7 +696,7 @@ public:
return false; return false;
} }
} }
if (resume_threads.empty()) if (resume_threads.empty())
{ {
result.AppendError ("no valid thread indexes were specified"); result.AppendError ("no valid thread indexes were specified");
@ -706,12 +709,12 @@ public:
result.AppendMessageWithFormat ("Resuming thread: "); result.AppendMessageWithFormat ("Resuming thread: ");
else else
result.AppendMessageWithFormat ("Resuming threads: "); result.AppendMessageWithFormat ("Resuming threads: ");
for (uint32_t idx=0; idx<num_threads; ++idx) for (uint32_t idx=0; idx<num_threads; ++idx)
{ {
Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
std::vector<Thread *>::iterator this_thread_pos = find(resume_threads.begin(), resume_threads.end(), thread); std::vector<Thread *>::iterator this_thread_pos = find(resume_threads.begin(), resume_threads.end(), thread);
if (this_thread_pos != resume_threads.end()) if (this_thread_pos != resume_threads.end())
{ {
resume_threads.erase(this_thread_pos); resume_threads.erase(this_thread_pos);
@ -719,7 +722,7 @@ public:
result.AppendMessageWithFormat ("%u, ", thread->GetIndexID()); result.AppendMessageWithFormat ("%u, ", thread->GetIndexID());
else else
result.AppendMessageWithFormat ("%u ", thread->GetIndexID()); result.AppendMessageWithFormat ("%u ", thread->GetIndexID());
thread->SetResumeState (eStateRunning); thread->SetResumeState (eStateRunning);
} }
else else
@ -732,6 +735,11 @@ public:
} }
else else
{ {
// These two lines appear at the beginning of both blocks in
// this if..else, but that is because we need to release the
// lock before calling process->Resume below.
Mutex::Locker locker (process->GetThreadList().GetMutex());
const uint32_t num_threads = process->GetThreadList().GetSize();
Thread *current_thread = process->GetThreadList().GetSelectedThread().get(); Thread *current_thread = process->GetThreadList().GetSelectedThread().get();
if (current_thread == NULL) if (current_thread == NULL)
{ {
@ -754,7 +762,8 @@ public:
} }
} }
} }
// We should not be holding the thread list lock when we do this.
Error error (process->Resume()); Error error (process->Resume());
if (error.Success()) if (error.Success())
{ {
@ -762,7 +771,7 @@ public:
if (synchronous_execution) if (synchronous_execution)
{ {
state = process->WaitForProcessToStop (NULL); state = process->WaitForProcessToStop (NULL);
result.SetDidChangeProcessState (true); result.SetDidChangeProcessState (true);
result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state));
result.SetStatus (eReturnStatusSuccessFinishNoResult); result.SetStatus (eReturnStatusSuccessFinishNoResult);