2010-06-09 00:52:24 +08:00
|
|
|
//===-- ThreadList.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2010-09-04 01:10:42 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2013-05-11 01:19:04 +08:00
|
|
|
#include "lldb/Core/State.h"
|
2010-09-04 01:10:42 +08:00
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/ThreadList.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
#include "lldb/Target/ThreadPlan.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
2015-03-19 05:31:45 +08:00
|
|
|
#include "lldb/Utility/ConvertEnum.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
ThreadList::ThreadList (Process *process) :
|
2014-09-06 03:13:15 +08:00
|
|
|
ThreadCollection(),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_process (process),
|
|
|
|
m_stop_id (0),
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid (LLDB_INVALID_THREAD_ID)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadList::ThreadList (const ThreadList &rhs) :
|
2014-09-06 03:13:15 +08:00
|
|
|
ThreadCollection(),
|
2013-05-08 02:35:34 +08:00
|
|
|
m_process (rhs.m_process),
|
|
|
|
m_stop_id (rhs.m_stop_id),
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// Use the assignment operator since it uses the mutex
|
|
|
|
*this = rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ThreadList&
|
|
|
|
ThreadList::operator = (const ThreadList& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
// Lock both mutexes to make sure neither side changes anyone on us
|
2015-07-22 08:16:02 +08:00
|
|
|
// while the assignment occurs
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
m_process = rhs.m_process;
|
|
|
|
m_stop_id = rhs.m_stop_id;
|
|
|
|
m_threads = rhs.m_threads;
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid = rhs.m_selected_tid;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ThreadList::~ThreadList()
|
|
|
|
{
|
2013-03-29 02:33:53 +08:00
|
|
|
// Clear the thread list. Clear will take the mutex lock
|
|
|
|
// which will ensure that if anyone is using the list
|
|
|
|
// they won't get it removed while using it.
|
|
|
|
Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ThreadList::GetStopID () const
|
|
|
|
{
|
|
|
|
return m_stop_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadList::SetStopID (uint32_t stop_id)
|
|
|
|
{
|
|
|
|
m_stop_id = stop_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ThreadList::GetSize (bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
return m_threads.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadSP
|
|
|
|
ThreadList::GetThreadAtIndex (uint32_t idx, bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
if (idx < m_threads.size())
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadSP
|
|
|
|
ThreadList::FindThreadByID (lldb::tid_t tid, bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
uint32_t idx = 0;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
if (m_threads[idx]->GetID() == tid)
|
|
|
|
{
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
ThreadSP
|
|
|
|
ThreadList::FindThreadByProtocolID (lldb::tid_t tid, bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2013-05-02 05:54:04 +08:00
|
|
|
|
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
uint32_t idx = 0;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
if (m_threads[idx]->GetProtocolID() == tid)
|
|
|
|
{
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-09 06:10:01 +08:00
|
|
|
ThreadSP
|
|
|
|
ThreadList::RemoveThreadByID (lldb::tid_t tid, bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2013-01-09 06:10:01 +08:00
|
|
|
|
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
uint32_t idx = 0;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
if (m_threads[idx]->GetID() == tid)
|
|
|
|
{
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
m_threads.erase(m_threads.begin()+idx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
ThreadSP
|
|
|
|
ThreadList::RemoveThreadByProtocolID (lldb::tid_t tid, bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2013-05-02 05:54:04 +08:00
|
|
|
|
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
uint32_t idx = 0;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
if (m_threads[idx]->GetProtocolID() == tid)
|
|
|
|
{
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
m_threads.erase(m_threads.begin()+idx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
ThreadSP
|
|
|
|
ThreadList::GetThreadSPForThreadPtr (Thread *thread_ptr)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
if (thread_ptr)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
uint32_t idx = 0;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
if (m_threads[idx].get() == thread_ptr)
|
|
|
|
{
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ThreadSP
|
|
|
|
ThreadList::FindThreadByIndexID (uint32_t index_id, bool can_update)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (can_update)
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (uint32_t idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
if (m_threads[idx]->GetIndexID() == index_id)
|
|
|
|
{
|
|
|
|
thread_sp = m_threads[idx];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return thread_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadList::ShouldStop (Event *event_ptr)
|
|
|
|
{
|
|
|
|
// Running events should never stop, obviously...
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-11-16 06:44:04 +08:00
|
|
|
// The ShouldStop method of the threads can do a whole lot of work,
|
2014-04-09 05:33:21 +08:00
|
|
|
// figuring out whether the thread plan conditions are met. So we don't want
|
2012-11-16 06:44:04 +08:00
|
|
|
// to keep the ThreadList locked the whole time we are doing this.
|
|
|
|
// FIXME: It is possible that running code could cause new threads
|
2015-05-19 07:24:32 +08:00
|
|
|
// to be created. If that happens, we will miss asking them whether
|
|
|
|
// they should stop. This is not a big deal since we haven't had
|
2012-11-16 06:44:04 +08:00
|
|
|
// a chance to hang any interesting operations on those threads yet.
|
|
|
|
|
|
|
|
collection threads_copy;
|
|
|
|
{
|
|
|
|
// Scope for locker
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-11-16 06:44:04 +08:00
|
|
|
m_process->UpdateThreadListIfNeeded();
|
2015-11-07 06:45:57 +08:00
|
|
|
for (lldb::ThreadSP thread_sp : m_threads)
|
|
|
|
{
|
|
|
|
// This is an optimization... If we didn't let a thread run in between the previous stop and this
|
|
|
|
// one, we shouldn't have to consult it for ShouldStop. So just leave it off the list we are going to
|
|
|
|
// inspect.
|
2015-11-07 10:16:31 +08:00
|
|
|
// On Linux, if a thread-specific conditional breakpoint was hit, it won't necessarily be the thread
|
|
|
|
// that hit the breakpoint itself that evaluates the conditional expression, so the thread that hit
|
|
|
|
// the breakpoint could still be asked to stop, even though it hasn't been allowed to run since the
|
|
|
|
// previous stop.
|
|
|
|
if (thread_sp->GetTemporaryResumeState () != eStateSuspended || thread_sp->IsStillAtLastBreakpointHit())
|
2015-11-07 06:45:57 +08:00
|
|
|
threads_copy.push_back(thread_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is possible the threads we were allowing to run all exited and then maybe the user interrupted
|
|
|
|
// or something, then fall back on looking at all threads:
|
|
|
|
|
|
|
|
if (threads_copy.size() == 0)
|
|
|
|
threads_copy = m_threads;
|
2012-11-16 06:44:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
collection::iterator pos, end = threads_copy.end();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-04 01:10:42 +08:00
|
|
|
if (log)
|
2011-10-15 08:23:43 +08:00
|
|
|
{
|
|
|
|
log->PutCString("");
|
2015-11-07 06:45:57 +08:00
|
|
|
log->Printf ("ThreadList::%s: %" PRIu64 " threads, %" PRIu64 " unsuspended threads",
|
|
|
|
__FUNCTION__,
|
|
|
|
(uint64_t)m_threads.size(),
|
|
|
|
(uint64_t)threads_copy.size());
|
2011-10-15 08:23:43 +08:00
|
|
|
}
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2013-03-22 05:46:56 +08:00
|
|
|
bool did_anybody_stop_for_a_reason = false;
|
2014-04-09 05:33:21 +08:00
|
|
|
|
|
|
|
// If the event is an Interrupt event, then we're going to stop no matter what. Otherwise, presume we won't stop.
|
2013-04-17 06:53:24 +08:00
|
|
|
bool should_stop = false;
|
2014-04-09 05:33:21 +08:00
|
|
|
if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr))
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("ThreadList::%s handling interrupt event, should stop set to true", __FUNCTION__);
|
|
|
|
|
|
|
|
should_stop = true;
|
|
|
|
}
|
2013-04-17 06:53:24 +08:00
|
|
|
|
|
|
|
// Now we run through all the threads and get their stop info's. We want to make sure to do this first before
|
|
|
|
// we start running the ShouldStop, because one thread's ShouldStop could destroy information (like deleting a
|
|
|
|
// thread specific breakpoint another thread had stopped at) which could lead us to compute the StopInfo incorrectly.
|
|
|
|
// We don't need to use it here, we just want to make sure it gets computed.
|
|
|
|
|
|
|
|
for (pos = threads_copy.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
|
|
|
thread_sp->GetStopInfo();
|
|
|
|
}
|
2013-03-22 05:46:56 +08:00
|
|
|
|
2012-11-16 06:44:04 +08:00
|
|
|
for (pos = threads_copy.begin(); pos != end; ++pos)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2014-01-15 11:32:42 +08:00
|
|
|
// We should never get a stop for which no thread had a stop reason, but sometimes we do see this -
|
|
|
|
// for instance when we first connect to a remote stub. In that case we should stop, since we can't figure out
|
|
|
|
// the right thing to do and stopping gives the user control over what to do in this instance.
|
|
|
|
//
|
|
|
|
// Note, this causes a problem when you have a thread specific breakpoint, and a bunch of threads hit the breakpoint,
|
|
|
|
// but not the thread which we are waiting for. All the threads that are not "supposed" to hit the breakpoint
|
|
|
|
// are marked as having no stop reason, which is right, they should not show a stop reason. But that triggers this
|
|
|
|
// code and causes us to stop seemingly for no reason.
|
|
|
|
//
|
|
|
|
// Since the only way we ever saw this error was on first attach, I'm only going to trigger set did_anybody_stop_for_a_reason
|
|
|
|
// to true unless this is the first stop.
|
|
|
|
//
|
|
|
|
// If this becomes a problem, we'll have to have another StopReason like "StopInfoHidden" which will look invalid
|
|
|
|
// everywhere but at this check.
|
|
|
|
|
2014-01-18 01:31:06 +08:00
|
|
|
if (thread_sp->GetProcess()->GetStopID() > 1)
|
2014-01-15 11:32:42 +08:00
|
|
|
did_anybody_stop_for_a_reason = true;
|
|
|
|
else
|
|
|
|
did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
|
2013-03-22 05:46:56 +08:00
|
|
|
|
2011-10-15 08:23:43 +08:00
|
|
|
const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
|
2010-09-04 01:10:42 +08:00
|
|
|
if (thread_should_stop)
|
|
|
|
should_stop |= true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-06-19 12:45:32 +08:00
|
|
|
|
2013-03-22 05:46:56 +08:00
|
|
|
if (!should_stop && !did_anybody_stop_for_a_reason)
|
|
|
|
{
|
|
|
|
should_stop = true;
|
|
|
|
if (log)
|
|
|
|
log->Printf ("ThreadList::%s we stopped but no threads had a stop reason, overriding should_stop and stopping.", __FUNCTION__);
|
|
|
|
}
|
|
|
|
|
2010-09-04 01:10:42 +08:00
|
|
|
if (log)
|
2011-10-15 08:23:43 +08:00
|
|
|
log->Printf ("ThreadList::%s overall should_stop = %i", __FUNCTION__, should_stop);
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (should_stop)
|
|
|
|
{
|
2012-11-16 06:44:04 +08:00
|
|
|
for (pos = threads_copy.begin(); pos != end; ++pos)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
|
|
|
thread_sp->WillStop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return should_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vote
|
|
|
|
ThreadList::ShouldReportStop (Event *event_ptr)
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Vote result = eVoteNoOpinion;
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2010-09-04 01:10:42 +08:00
|
|
|
|
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("ThreadList::%s %" PRIu64 " threads", __FUNCTION__, (uint64_t)m_threads.size());
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Run through the threads and ask whether we should report this event.
|
|
|
|
// For stopping, a YES vote wins over everything. A NO vote wins over NO opinion.
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
2012-02-01 07:09:20 +08:00
|
|
|
const Vote vote = thread_sp->ShouldReportStop (event_ptr);
|
|
|
|
switch (vote)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2012-02-01 07:09:20 +08:00
|
|
|
case eVoteNoOpinion:
|
|
|
|
continue;
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2012-02-01 07:09:20 +08:00
|
|
|
case eVoteYes:
|
|
|
|
result = eVoteYes;
|
|
|
|
break;
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2012-02-01 07:09:20 +08:00
|
|
|
case eVoteNo:
|
|
|
|
if (result == eVoteNoOpinion)
|
|
|
|
{
|
|
|
|
result = eVoteNo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("ThreadList::%s thread 0x%4.4" PRIx64 ": voted %s, but lost out because result was %s",
|
2012-02-01 07:09:20 +08:00
|
|
|
__FUNCTION__,
|
|
|
|
thread_sp->GetID (),
|
|
|
|
GetVoteAsCString (vote),
|
|
|
|
GetVoteAsCString (result));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-02-01 07:09:20 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-04 01:10:42 +08:00
|
|
|
if (log)
|
2011-10-15 08:23:43 +08:00
|
|
|
log->Printf ("ThreadList::%s returning %s", __FUNCTION__, GetVoteAsCString (result));
|
2010-06-09 00:52:24 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 08:35:16 +08:00
|
|
|
void
|
|
|
|
ThreadList::SetShouldReportStop (Vote vote)
|
|
|
|
{
|
|
|
|
Mutex::Locker locker(GetMutex());
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
|
|
|
thread_sp->SetShouldReportStop (vote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Vote
|
|
|
|
ThreadList::ShouldReportRun (Event *event_ptr)
|
|
|
|
{
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-09-04 01:10:42 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Vote result = eVoteNoOpinion;
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
|
|
|
|
// Run through the threads and ask whether we should report this event.
|
|
|
|
// The rule is NO vote wins over everything, a YES vote wins over no opinion.
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2011-01-24 12:11:25 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
2011-01-24 12:11:25 +08:00
|
|
|
if ((*pos)->GetResumeState () != eStateSuspended)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-01-24 12:11:25 +08:00
|
|
|
switch ((*pos)->ShouldReportRun (event_ptr))
|
|
|
|
{
|
|
|
|
case eVoteNoOpinion:
|
|
|
|
continue;
|
|
|
|
case eVoteYes:
|
|
|
|
if (result == eVoteNoOpinion)
|
|
|
|
result = eVoteYes;
|
|
|
|
break;
|
|
|
|
case eVoteNo:
|
2011-01-24 13:36:47 +08:00
|
|
|
if (log)
|
2012-11-30 05:49:15 +08:00
|
|
|
log->Printf ("ThreadList::ShouldReportRun() thread %d (0x%4.4" PRIx64 ") says don't report.",
|
2011-01-24 13:36:47 +08:00
|
|
|
(*pos)->GetIndexID(),
|
|
|
|
(*pos)->GetID());
|
2011-01-24 12:11:25 +08:00
|
|
|
result = eVoteNo;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadList::Clear()
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
m_stop_id = 0;
|
|
|
|
m_threads.clear();
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid = LLDB_INVALID_THREAD_ID;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-01-30 04:56:30 +08:00
|
|
|
void
|
|
|
|
ThreadList::Destroy()
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2012-01-30 04:56:30 +08:00
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (uint32_t idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
|
|
|
m_threads[idx]->DestroyThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
ThreadList::RefreshStateAfterStop ()
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
m_process->UpdateThreadListIfNeeded();
|
2011-01-22 09:33:44 +08:00
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2011-10-15 08:23:43 +08:00
|
|
|
if (log && log->GetVerbose())
|
2011-01-22 09:33:44 +08:00
|
|
|
log->Printf ("Turning off notification of new threads while single stepping a thread.");
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
(*pos)->RefreshStateAfterStop ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadList::DiscardThreadPlans ()
|
|
|
|
{
|
|
|
|
// You don't need to update the thread list here, because only threads
|
|
|
|
// that you currently know about have any thread plans.
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
(*pos)->DiscardThreadPlans (true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThreadList::WillResume ()
|
|
|
|
{
|
|
|
|
// Run through the threads and perform their momentary actions.
|
|
|
|
// But we only do this for threads that are running, user suspended
|
|
|
|
// threads stay where they are.
|
|
|
|
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
m_process->UpdateThreadListIfNeeded();
|
|
|
|
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
|
2010-07-14 10:27:20 +08:00
|
|
|
// See if any thread wants to run stopping others. If it does, then we won't
|
|
|
|
// setup the other threads for resume, since they aren't going to get a chance
|
|
|
|
// to run. This is necessary because the SetupForResume might add "StopOthers"
|
|
|
|
// plans which would then get to be part of the who-gets-to-run negotiation, but
|
|
|
|
// they're coming in after the fact, and the threads that are already set up should
|
|
|
|
// take priority.
|
|
|
|
|
|
|
|
bool wants_solo_run = false;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
2010-07-14 10:27:20 +08:00
|
|
|
{
|
2015-11-14 05:28:53 +08:00
|
|
|
if ((*pos)->GetResumeState() != eStateSuspended && (*pos)->GetCurrentPlan() &&
|
2010-07-14 10:27:20 +08:00
|
|
|
(*pos)->GetCurrentPlan()->StopOthers())
|
|
|
|
{
|
2013-05-09 09:55:29 +08:00
|
|
|
if ((*pos)->IsOperatingSystemPluginThread() && !(*pos)->GetBackingThread())
|
|
|
|
continue;
|
2010-07-14 10:27:20 +08:00
|
|
|
wants_solo_run = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-22 09:33:44 +08:00
|
|
|
if (wants_solo_run)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2011-10-15 08:23:43 +08:00
|
|
|
if (log && log->GetVerbose())
|
2011-01-22 09:33:44 +08:00
|
|
|
log->Printf ("Turning on notification of new threads while single stepping a thread.");
|
|
|
|
m_process->StartNoticingNewThreads();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
|
2011-10-15 08:23:43 +08:00
|
|
|
if (log && log->GetVerbose())
|
2011-01-22 09:33:44 +08:00
|
|
|
log->Printf ("Turning off notification of new threads while single stepping a thread.");
|
|
|
|
m_process->StopNoticingNewThreads();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-07-14 10:27:20 +08:00
|
|
|
// Give all the threads that are likely to run a last chance to set up their state before we
|
|
|
|
// negotiate who is actually going to get a chance to run...
|
|
|
|
// Don't set to resume suspended threads, and if any thread wanted to stop others, only
|
|
|
|
// call setup on the threads that request StopOthers...
|
|
|
|
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if ((*pos)->GetResumeState() != eStateSuspended
|
|
|
|
&& (!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers()))
|
|
|
|
{
|
2013-05-09 09:55:29 +08:00
|
|
|
if ((*pos)->IsOperatingSystemPluginThread() && !(*pos)->GetBackingThread())
|
|
|
|
continue;
|
2010-07-14 10:27:20 +08:00
|
|
|
(*pos)->SetupForResume ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// Now go through the threads and see if any thread wants to run just itself.
|
|
|
|
// if so then pick one and run it.
|
2010-07-14 10:27:20 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
ThreadList run_me_only_list (m_process);
|
|
|
|
|
|
|
|
run_me_only_list.SetStopID(m_process->GetStopID());
|
|
|
|
|
|
|
|
bool run_only_current_thread = false;
|
|
|
|
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
2010-10-20 08:39:53 +08:00
|
|
|
if (thread_sp->GetResumeState() != eStateSuspended &&
|
2010-06-09 00:52:24 +08:00
|
|
|
thread_sp->GetCurrentPlan()->StopOthers())
|
|
|
|
{
|
2013-05-09 09:55:29 +08:00
|
|
|
if ((*pos)->IsOperatingSystemPluginThread() && !(*pos)->GetBackingThread())
|
|
|
|
continue;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// You can't say "stop others" and also want yourself to be suspended.
|
|
|
|
assert (thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
|
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
if (thread_sp == GetSelectedThread())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2015-06-03 04:26:13 +08:00
|
|
|
// If the currently selected thread wants to run on its own, always let it.
|
2010-06-09 00:52:24 +08:00
|
|
|
run_only_current_thread = true;
|
|
|
|
run_me_only_list.Clear();
|
|
|
|
run_me_only_list.AddThread (thread_sp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
run_me_only_list.AddThread (thread_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-01 09:02:41 +08:00
|
|
|
bool need_to_resume = true;
|
|
|
|
|
2013-05-09 09:55:29 +08:00
|
|
|
if (run_me_only_list.GetSize (false) == 0)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// Everybody runs as they wish:
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
2012-06-01 04:47:56 +08:00
|
|
|
StateType run_state;
|
|
|
|
if (thread_sp->GetResumeState() != eStateSuspended)
|
|
|
|
run_state = thread_sp->GetCurrentPlan()->RunState();
|
|
|
|
else
|
|
|
|
run_state = eStateSuspended;
|
2013-05-02 05:54:04 +08:00
|
|
|
if (!thread_sp->ShouldResume(run_state))
|
2012-09-01 09:02:41 +08:00
|
|
|
need_to_resume = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ThreadSP thread_to_run;
|
|
|
|
|
|
|
|
if (run_only_current_thread)
|
|
|
|
{
|
2010-08-27 05:32:51 +08:00
|
|
|
thread_to_run = GetSelectedThread();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else if (run_me_only_list.GetSize (false) == 1)
|
|
|
|
{
|
|
|
|
thread_to_run = run_me_only_list.GetThreadAtIndex (0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int random_thread = (int)
|
|
|
|
((run_me_only_list.GetSize (false) * (double) rand ()) / (RAND_MAX + 1.0));
|
|
|
|
thread_to_run = run_me_only_list.GetThreadAtIndex (random_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
ThreadSP thread_sp(*pos);
|
|
|
|
if (thread_sp == thread_to_run)
|
2012-09-01 09:02:41 +08:00
|
|
|
{
|
2013-05-02 05:54:04 +08:00
|
|
|
if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
|
2012-09-01 09:02:41 +08:00
|
|
|
need_to_resume = false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2013-05-02 05:54:04 +08:00
|
|
|
thread_sp->ShouldResume (eStateSuspended);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-01 09:02:41 +08:00
|
|
|
return need_to_resume;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadList::DidResume ()
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2010-06-09 00:52:24 +08:00
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
// Don't clear out threads that aren't going to get a chance to run, rather
|
|
|
|
// leave their state for the next time around.
|
|
|
|
ThreadSP thread_sp(*pos);
|
|
|
|
if (thread_sp->GetResumeState() != eStateSuspended)
|
|
|
|
thread_sp->DidResume ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 01:19:04 +08:00
|
|
|
void
|
|
|
|
ThreadList::DidStop ()
|
|
|
|
{
|
|
|
|
Mutex::Locker locker(GetMutex());
|
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
{
|
|
|
|
// Notify threads that the process just stopped.
|
|
|
|
// Note, this currently assumes that all threads in the list
|
|
|
|
// stop when the process stops. In the future we will want to support
|
|
|
|
// a debugging model where some threads continue to run while others
|
|
|
|
// are stopped. We either need to handle that somehow here or
|
|
|
|
// create a special thread list containing only threads which will
|
|
|
|
// stop in the code that calls this method (currently
|
|
|
|
// Process::SetPrivateState).
|
|
|
|
ThreadSP thread_sp(*pos);
|
|
|
|
if (StateIsRunningState(thread_sp->GetState()))
|
|
|
|
thread_sp->DidStop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
ThreadSP
|
2010-08-27 05:32:51 +08:00
|
|
|
ThreadList::GetSelectedThread ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2011-08-26 05:59:59 +08:00
|
|
|
ThreadSP thread_sp = FindThreadByID(m_selected_tid);
|
|
|
|
if (!thread_sp.get())
|
|
|
|
{
|
2011-09-13 09:13:16 +08:00
|
|
|
if (m_threads.size() == 0)
|
|
|
|
return thread_sp;
|
2011-08-26 05:59:59 +08:00
|
|
|
m_selected_tid = m_threads[0]->GetID();
|
|
|
|
thread_sp = m_threads[0];
|
|
|
|
}
|
|
|
|
return thread_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-12-11 10:31:48 +08:00
|
|
|
ThreadList::SetSelectedThreadByID (lldb::tid_t tid, bool notify)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2011-09-09 06:13:49 +08:00
|
|
|
ThreadSP selected_thread_sp(FindThreadByID(tid));
|
|
|
|
if (selected_thread_sp)
|
|
|
|
{
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid = tid;
|
2011-09-09 06:13:49 +08:00
|
|
|
selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid = LLDB_INVALID_THREAD_ID;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-12-11 10:31:48 +08:00
|
|
|
if (notify)
|
|
|
|
NotifySelectedThreadChanged(m_selected_tid);
|
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
return m_selected_tid != LLDB_INVALID_THREAD_ID;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-12-11 10:31:48 +08:00
|
|
|
ThreadList::SetSelectedThreadByIndexID (uint32_t index_id, bool notify)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2011-09-09 06:13:49 +08:00
|
|
|
ThreadSP selected_thread_sp (FindThreadByIndexID(index_id));
|
|
|
|
if (selected_thread_sp.get())
|
|
|
|
{
|
|
|
|
m_selected_tid = selected_thread_sp->GetID();
|
|
|
|
selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2010-08-27 05:32:51 +08:00
|
|
|
m_selected_tid = LLDB_INVALID_THREAD_ID;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-12-11 10:31:48 +08:00
|
|
|
if (notify)
|
|
|
|
NotifySelectedThreadChanged(m_selected_tid);
|
|
|
|
|
2010-08-27 05:32:51 +08:00
|
|
|
return m_selected_tid != LLDB_INVALID_THREAD_ID;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-12-11 10:31:48 +08:00
|
|
|
void
|
|
|
|
ThreadList::NotifySelectedThreadChanged (lldb::tid_t tid)
|
|
|
|
{
|
|
|
|
ThreadSP selected_thread_sp (FindThreadByID(tid));
|
|
|
|
if (selected_thread_sp->EventTypeHasListeners(Thread::eBroadcastBitThreadSelected))
|
|
|
|
selected_thread_sp->BroadcastEvent(Thread::eBroadcastBitThreadSelected,
|
|
|
|
new Thread::ThreadEventData(selected_thread_sp));
|
|
|
|
}
|
|
|
|
|
2011-08-22 10:49:39 +08:00
|
|
|
void
|
|
|
|
ThreadList::Update (ThreadList &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
{
|
|
|
|
// Lock both mutexes to make sure neither side changes anyone on us
|
2015-07-22 08:16:02 +08:00
|
|
|
// while the assignment occurs
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2011-08-22 10:49:39 +08:00
|
|
|
m_process = rhs.m_process;
|
|
|
|
m_stop_id = rhs.m_stop_id;
|
|
|
|
m_threads.swap(rhs.m_threads);
|
|
|
|
m_selected_tid = rhs.m_selected_tid;
|
2012-01-30 04:56:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Now we look for threads that we are done with and
|
|
|
|
// make sure to clear them up as much as possible so
|
|
|
|
// anyone with a shared pointer will still have a reference,
|
|
|
|
// but the thread won't be of much use. Using std::weak_ptr
|
|
|
|
// for all backward references (such as a thread to a process)
|
|
|
|
// will eventually solve this issue for us, but for now, we
|
|
|
|
// need to work around the issue
|
|
|
|
collection::iterator rhs_pos, rhs_end = rhs.m_threads.end();
|
|
|
|
for (rhs_pos = rhs.m_threads.begin(); rhs_pos != rhs_end; ++rhs_pos)
|
|
|
|
{
|
|
|
|
const lldb::tid_t tid = (*rhs_pos)->GetID();
|
|
|
|
bool thread_is_alive = false;
|
|
|
|
const uint32_t num_threads = m_threads.size();
|
|
|
|
for (uint32_t idx = 0; idx < num_threads; ++idx)
|
|
|
|
{
|
2015-09-17 05:20:44 +08:00
|
|
|
ThreadSP backing_thread = m_threads[idx]->GetBackingThread();
|
|
|
|
if (m_threads[idx]->GetID() == tid || (backing_thread && backing_thread->GetID() == tid))
|
2012-01-30 04:56:30 +08:00
|
|
|
{
|
|
|
|
thread_is_alive = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!thread_is_alive)
|
|
|
|
(*rhs_pos)->DestroyThread();
|
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-18 10:38:05 +08:00
|
|
|
void
|
|
|
|
ThreadList::Flush ()
|
|
|
|
{
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex::Locker locker(GetMutex());
|
2012-05-18 10:38:05 +08:00
|
|
|
collection::iterator pos, end = m_threads.end();
|
|
|
|
for (pos = m_threads.begin(); pos != end; ++pos)
|
|
|
|
(*pos)->Flush ();
|
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
|
2013-05-08 02:35:34 +08:00
|
|
|
Mutex &
|
|
|
|
ThreadList::GetMutex ()
|
|
|
|
{
|
|
|
|
return m_process->m_thread_mutex;
|
|
|
|
}
|
|
|
|
|