44 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
64 return expr_thread_sp;
83 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
91 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
103 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
110 const uint32_t num_threads =
m_threads.size();
111 for (idx = 0; idx < num_threads; ++idx) {
121 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
128 const uint32_t num_threads =
m_threads.size();
129 for (idx = 0; idx < num_threads; ++idx) {
130 if (
m_threads[idx]->GetProtocolID() == tid) {
139 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
146 const uint32_t num_threads =
m_threads.size();
147 for (idx = 0; idx < num_threads; ++idx) {
159 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
166 const uint32_t num_threads =
m_threads.size();
167 for (idx = 0; idx < num_threads; ++idx) {
168 if (
m_threads[idx]->GetProtocolID() == tid) {
180 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
183 const uint32_t num_threads =
m_threads.size();
184 for (idx = 0; idx < num_threads; ++idx) {
185 if (
m_threads[idx].get() == thread_ptr) {
195 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
198 const uint32_t num_threads =
m_threads.size();
199 for (uint32_t idx = 0; idx < num_threads; ++idx) {
209 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
215 const uint32_t num_threads =
m_threads.size();
216 for (uint32_t idx = 0; idx < num_threads; ++idx) {
217 if (
m_threads[idx]->GetIndexID() == index_id) {
241 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
256 thread_sp->IsStillAtLastBreakpointHit()
257 || thread_sp->ShouldRunBeforePublicStop())
258 threads_copy.push_back(thread_sp);
265 if (threads_copy.size() == 0)
269 collection::iterator pos, end = threads_copy.end();
274 "ThreadList::%s: %" PRIu64
" threads, %" PRIu64
275 " unsuspended threads",
276 __FUNCTION__, (uint64_t)
m_threads.size(),
277 (uint64_t)threads_copy.size());
280 bool did_anybody_stop_for_a_reason =
false;
284 bool should_stop =
false;
287 log,
"ThreadList::%s handling interrupt event, should stop set to true",
300 for (pos = threads_copy.begin(); pos != end; ++pos) {
302 thread_sp->GetStopInfo();
308 bool a_thread_needs_to_run =
false;
309 for (pos = threads_copy.begin(); pos != end; ++pos) {
332 if (thread_sp->GetProcess()->GetStopID() > 1)
333 did_anybody_stop_for_a_reason =
true;
335 did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
337 const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
339 if (thread_should_stop)
342 bool this_thread_forces_run = thread_sp->ShouldRunBeforePublicStop();
343 a_thread_needs_to_run |= this_thread_forces_run;
344 if (this_thread_forces_run)
346 "ThreadList::{0} thread: {1:x}, "
347 "says it needs to run before public stop.",
348 __FUNCTION__, thread_sp->GetID());
352 if (a_thread_needs_to_run) {
354 }
else if (!should_stop && !did_anybody_stop_for_a_reason) {
357 "ThreadList::%s we stopped but no threads had a stop reason, "
358 "overriding should_stop and stopping.",
362 LLDB_LOGF(log,
"ThreadList::%s overall should_stop = %i", __FUNCTION__,
366 for (pos = threads_copy.begin(); pos != end; ++pos) {
368 thread_sp->WillStop();
376 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
380 collection::iterator pos, end =
m_threads.end();
384 LLDB_LOGF(log,
"ThreadList::%s %" PRIu64
" threads", __FUNCTION__,
391 for (pos =
m_threads.begin(); pos != end; ++pos) {
393 if (thread_sp->ShouldRunBeforePublicStop()) {
394 LLDB_LOG(log,
"Thread {0:x} has private business to complete, overrode "
395 "the should report stop.", thread_sp->GetID());
400 const Vote vote = thread_sp->ShouldReportStop(event_ptr);
414 "Thread {0:x} voted {1}, but lost out because result was {2}",
415 thread_sp->GetID(), vote, result);
420 LLDB_LOG(log,
"Returning {0}", result);
425 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
428 collection::iterator pos, end =
m_threads.end();
429 for (pos =
m_threads.begin(); pos != end; ++pos) {
431 thread_sp->SetShouldReportStop(vote);
437 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
441 collection::iterator pos, end =
m_threads.end();
448 for (pos =
m_threads.begin(); pos != end; ++pos) {
450 switch ((*pos)->ShouldReportRun(event_ptr)) {
459 "ThreadList::ShouldReportRun() thread %d (0x%4.4" PRIx64
460 ") says don't report.",
461 (*pos)->GetIndexID(), (*pos)->GetID());
471 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
478 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
479 const uint32_t num_threads =
m_threads.size();
480 for (uint32_t idx = 0; idx < num_threads; ++idx) {
486 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
493 "Turning off notification of new threads while single stepping "
496 collection::iterator pos, end =
m_threads.end();
497 for (pos =
m_threads.begin(); pos != end; ++pos)
498 (*pos)->RefreshStateAfterStop();
504 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
506 collection::iterator pos, end =
m_threads.end();
507 for (pos =
m_threads.begin(); pos != end; ++pos)
508 (*pos)->DiscardThreadPlans(
true);
516 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
519 collection::iterator pos, end =
m_threads.end();
528 bool wants_solo_run =
false;
530 for (pos =
m_threads.begin(); pos != end; ++pos) {
532 "thread should not have null thread plan");
534 (*pos)->GetCurrentPlan()->StopOthers()) {
535 if ((*pos)->IsOperatingSystemPluginThread() &&
536 !(*pos)->GetBackingThread())
538 wants_solo_run =
true;
543 if (wants_solo_run) {
546 LLDB_LOGF(log,
"Turning on notification of new threads while single "
547 "stepping a thread.");
552 LLDB_LOGF(log,
"Turning off notification of new threads while single "
553 "stepping a thread.");
562 for (pos =
m_threads.begin(); pos != end; ++pos) {
564 (!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) {
565 if ((*pos)->IsOperatingSystemPluginThread() &&
566 !(*pos)->GetBackingThread())
568 (*pos)->SetupForResume();
587 for (pos =
m_threads.begin(); pos != end; ++pos) {
590 thread_sp->GetCurrentPlan()->StopOthers()) {
591 if ((*pos)->IsOperatingSystemPluginThread() &&
592 !(*pos)->GetBackingThread())
600 stop_others_thread_sp = thread_sp;
602 if (thread_sp->ShouldRunBeforePublicStop()) {
604 stop_others_thread_sp = thread_sp;
610 bool need_to_resume =
true;
612 if (run_me_only_list.
GetSize(
false) == 0) {
614 for (pos =
m_threads.begin(); pos != end; ++pos) {
618 run_state = thread_sp->GetCurrentPlan()->RunState();
621 if (!thread_sp->ShouldResume(run_state))
622 need_to_resume =
false;
627 if (stop_others_thread_sp) {
628 thread_to_run = stop_others_thread_sp;
629 }
else if (run_me_only_list.
GetSize(
false) == 1) {
633 (int)((run_me_only_list.
GetSize(
false) * (
double)rand()) /
638 for (pos =
m_threads.begin(); pos != end; ++pos) {
640 if (thread_sp == thread_to_run) {
644 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
645 need_to_resume =
false;
651 return need_to_resume;
655 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
656 collection::iterator pos, end =
m_threads.end();
657 for (pos =
m_threads.begin(); pos != end; ++pos) {
662 thread_sp->DidResume();
667 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
668 collection::iterator pos, end =
m_threads.end();
669 for (pos =
m_threads.begin(); pos != end; ++pos) {
679 thread_sp->DidStop();
684 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
686 if (!thread_sp.get()) {
696 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
698 if (selected_thread_sp) {
700 selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
711 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
713 if (selected_thread_sp.get()) {
715 selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
727 if (selected_thread_sp->EventTypeHasListeners(
730 std::make_shared<Thread::ThreadEventData>(selected_thread_sp);
743 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
755 collection::iterator rhs_pos, rhs_end = rhs.
m_threads.end();
756 for (rhs_pos = rhs.
m_threads.begin(); rhs_pos != rhs_end; ++rhs_pos) {
759 if (!(*rhs_pos)->IsValid())
763 bool thread_is_alive =
false;
764 const uint32_t num_threads =
m_threads.size();
765 for (uint32_t idx = 0; idx < num_threads; ++idx) {
768 (backing_thread && backing_thread->GetID() == tid)) {
769 thread_is_alive =
true;
773 if (!thread_is_alive) {
774 (*rhs_pos)->DestroyThread();
781 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
782 collection::iterator pos, end =
m_threads.end();
783 for (pos =
m_threads.begin(); pos != end; ++pos)
795 m_tid = thread_sp->GetID();
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
void PutCString(const char *cstr)
static bool GetInterruptedFromEvent(const Event *event_ptr)
A plug-in interface definition class for debugging a process.
void UpdateThreadListIfNeeded()
std::recursive_mutex m_thread_mutex
virtual bool StopNoticingNewThreads()
Call this to turn off the stop & notice new threads mode.
uint32_t GetStopID() const
virtual bool StartNoticingNewThreads()
Call this to set the lldb in the mode where it breaks on new thread creations, and then auto-restarts...
std::vector< lldb::ThreadSP > collection
void AddThread(const lldb::ThreadSP &thread_sp)
ThreadList * m_thread_list
ExpressionExecutionThreadPusher(ThreadList &thread_list, lldb::tid_t tid)
lldb::ThreadSP RemoveThreadByID(lldb::tid_t tid, bool can_update=true)
lldb::ThreadSP GetSelectedThread()
bool ShouldStop(Event *event_ptr)
Vote ShouldReportStop(Event *event_ptr)
uint32_t GetStopID() const
bool SetSelectedThreadByIndexID(uint32_t index_id, bool notify=false)
lldb::ThreadSP FindThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
uint32_t GetSize(bool can_update=true)
void PopExpressionExecutionThread(lldb::tid_t tid)
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update=true)
Vote ShouldReportRun(Event *event_ptr)
void SetStopID(uint32_t stop_id)
lldb::ThreadSP GetThreadSPForThreadPtr(Thread *thread_ptr)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
uint32_t m_stop_id
The process stop ID that this thread list is valid for.
std::recursive_mutex & GetMutex() const override
lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update=true)
lldb::ThreadSP GetExpressionExecutionThread()
const ThreadList & operator=(const ThreadList &rhs)
Precondition: both thread lists must be belong to the same process.
void DiscardThreadPlans()
void RefreshStateAfterStop()
void Update(ThreadList &rhs)
Precondition: both thread lists must be belong to the same process.
lldb::ThreadSP GetBackingThread(const lldb::ThreadSP &real_thread)
bool WillResume()
The thread list asks tells all the threads it is about to resume.
void PushExpressionExecutionThread(lldb::tid_t tid)
void SetShouldReportStop(Vote vote)
lldb::tid_t m_selected_tid
For targets that need the notion of a current thread.
void NotifySelectedThreadChanged(lldb::tid_t tid)
lldb::ThreadSP RemoveThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
Process & m_process
The process that manages this thread list.
std::vector< lldb::tid_t > m_expression_tid_stack
@ eBroadcastBitThreadSelected
#define LLDB_INVALID_THREAD_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
std::shared_ptr< lldb_private::Thread > ThreadSP
StateType
Process and Thread States.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...