42 std::lock_guard<std::recursive_mutex> guard(
GetMutex(), std::adopt_lock);
43 std::lock_guard<std::recursive_mutex> rhs_guard(rhs.
GetMutex(),
65 return expr_thread_sp;
84 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
92 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
104 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
111 const uint32_t num_threads =
m_threads.size();
112 for (idx = 0; idx < num_threads; ++idx) {
122 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
129 const uint32_t num_threads =
m_threads.size();
130 for (idx = 0; idx < num_threads; ++idx) {
131 if (
m_threads[idx]->GetProtocolID() == tid) {
140 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
147 const uint32_t num_threads =
m_threads.size();
148 for (idx = 0; idx < num_threads; ++idx) {
160 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
167 const uint32_t num_threads =
m_threads.size();
168 for (idx = 0; idx < num_threads; ++idx) {
169 if (
m_threads[idx]->GetProtocolID() == tid) {
181 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
184 const uint32_t num_threads =
m_threads.size();
185 for (idx = 0; idx < num_threads; ++idx) {
186 if (
m_threads[idx].get() == thread_ptr) {
196 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
199 const uint32_t num_threads =
m_threads.size();
200 for (uint32_t idx = 0; idx < num_threads; ++idx) {
210 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
216 const uint32_t num_threads =
m_threads.size();
217 for (uint32_t idx = 0; idx < num_threads; ++idx) {
218 if (
m_threads[idx]->GetIndexID() == index_id) {
242 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
257 thread_sp->IsStillAtLastBreakpointHit()
258 || thread_sp->ShouldRunBeforePublicStop())
259 threads_copy.push_back(thread_sp);
266 if (threads_copy.size() == 0)
270 collection::iterator pos, end = threads_copy.end();
275 "ThreadList::%s: %" PRIu64
" threads, %" PRIu64
276 " unsuspended threads",
277 __FUNCTION__, (uint64_t)
m_threads.size(),
278 (uint64_t)threads_copy.size());
281 bool did_anybody_stop_for_a_reason =
false;
285 bool should_stop =
false;
288 log,
"ThreadList::%s handling interrupt event, should stop set to true",
301 for (pos = threads_copy.begin(); pos != end; ++pos) {
303 thread_sp->GetStopInfo();
309 bool a_thread_needs_to_run =
false;
310 for (pos = threads_copy.begin(); pos != end; ++pos) {
333 if (thread_sp->GetProcess()->GetStopID() > 1)
334 did_anybody_stop_for_a_reason =
true;
336 did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
338 const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
340 if (thread_should_stop)
343 bool this_thread_forces_run = thread_sp->ShouldRunBeforePublicStop();
344 a_thread_needs_to_run |= this_thread_forces_run;
345 if (this_thread_forces_run)
347 "ThreadList::{0} thread: {1:x}, "
348 "says it needs to run before public stop.",
349 __FUNCTION__, thread_sp->GetID());
353 if (a_thread_needs_to_run) {
355 }
else if (!should_stop && !did_anybody_stop_for_a_reason) {
358 "ThreadList::%s we stopped but no threads had a stop reason, "
359 "overriding should_stop and stopping.",
363 LLDB_LOGF(log,
"ThreadList::%s overall should_stop = %i", __FUNCTION__,
367 for (pos = threads_copy.begin(); pos != end; ++pos) {
369 thread_sp->WillStop();
377 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
381 collection::iterator pos, end =
m_threads.end();
385 LLDB_LOGF(log,
"ThreadList::%s %" PRIu64
" threads", __FUNCTION__,
392 for (pos =
m_threads.begin(); pos != end; ++pos) {
394 if (thread_sp->ShouldRunBeforePublicStop()) {
395 LLDB_LOG(log,
"Thread {0:x} has private business to complete, overrode "
396 "the should report stop.", thread_sp->GetID());
401 const Vote vote = thread_sp->ShouldReportStop(event_ptr);
415 "Thread {0:x} voted {1}, but lost out because result was {2}",
416 thread_sp->GetID(), vote, result);
421 LLDB_LOG(log,
"Returning {0}", result);
426 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
429 collection::iterator pos, end =
m_threads.end();
430 for (pos =
m_threads.begin(); pos != end; ++pos) {
432 thread_sp->SetShouldReportStop(vote);
438 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
442 collection::iterator pos, end =
m_threads.end();
449 for (pos =
m_threads.begin(); pos != end; ++pos) {
451 switch ((*pos)->ShouldReportRun(event_ptr)) {
460 "ThreadList::ShouldReportRun() thread %d (0x%4.4" PRIx64
461 ") says don't report.",
462 (*pos)->GetIndexID(), (*pos)->GetID());
472 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
479 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
480 const uint32_t num_threads =
m_threads.size();
481 for (uint32_t idx = 0; idx < num_threads; ++idx) {
487 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
494 "Turning off notification of new threads while single stepping "
497 collection::iterator pos, end =
m_threads.end();
498 for (pos =
m_threads.begin(); pos != end; ++pos)
499 (*pos)->RefreshStateAfterStop();
505 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
507 collection::iterator pos, end =
m_threads.end();
508 for (pos =
m_threads.begin(); pos != end; ++pos)
509 (*pos)->DiscardThreadPlans(
true);
517 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
520 collection::iterator pos, end =
m_threads.end();
529 bool wants_solo_run =
false;
531 for (pos =
m_threads.begin(); pos != end; ++pos) {
533 "thread should not have null thread plan");
535 (*pos)->GetCurrentPlan()->StopOthers()) {
536 if ((*pos)->IsOperatingSystemPluginThread() &&
537 !(*pos)->GetBackingThread())
539 wants_solo_run =
true;
544 if (wants_solo_run) {
547 LLDB_LOGF(log,
"Turning on notification of new threads while single "
548 "stepping a thread.");
553 LLDB_LOGF(log,
"Turning off notification of new threads while single "
554 "stepping a thread.");
563 for (pos =
m_threads.begin(); pos != end; ++pos) {
565 (!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) {
566 if ((*pos)->IsOperatingSystemPluginThread() &&
567 !(*pos)->GetBackingThread())
569 (*pos)->SetupForResume();
588 for (pos =
m_threads.begin(); pos != end; ++pos) {
591 thread_sp->GetCurrentPlan()->StopOthers()) {
592 if ((*pos)->IsOperatingSystemPluginThread() &&
593 !(*pos)->GetBackingThread())
601 stop_others_thread_sp = thread_sp;
603 if (thread_sp->ShouldRunBeforePublicStop()) {
605 stop_others_thread_sp = thread_sp;
611 bool need_to_resume =
true;
613 if (run_me_only_list.
GetSize(
false) == 0) {
615 for (pos =
m_threads.begin(); pos != end; ++pos) {
619 run_state = thread_sp->GetCurrentPlan()->RunState();
622 if (!thread_sp->ShouldResume(run_state))
623 need_to_resume =
false;
628 if (stop_others_thread_sp) {
629 thread_to_run = stop_others_thread_sp;
630 }
else if (run_me_only_list.
GetSize(
false) == 1) {
634 (int)((run_me_only_list.
GetSize(
false) * (
double)rand()) /
639 for (pos =
m_threads.begin(); pos != end; ++pos) {
641 if (thread_sp == thread_to_run) {
645 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
646 need_to_resume =
false;
652 return need_to_resume;
656 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
657 collection::iterator pos, end =
m_threads.end();
658 for (pos =
m_threads.begin(); pos != end; ++pos) {
663 thread_sp->DidResume();
668 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
669 collection::iterator pos, end =
m_threads.end();
670 for (pos =
m_threads.begin(); pos != end; ++pos) {
680 thread_sp->DidStop();
685 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
687 if (!thread_sp.get()) {
697 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
699 if (selected_thread_sp) {
701 selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
712 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
714 if (selected_thread_sp.get()) {
716 selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
728 if (selected_thread_sp->EventTypeHasListeners(
730 selected_thread_sp->BroadcastEvent(
739 std::scoped_lock<std::recursive_mutex, std::recursive_mutex> guard(
GetMutex(), rhs.
GetMutex());
752 collection::iterator rhs_pos, rhs_end = rhs.
m_threads.end();
753 for (rhs_pos = rhs.
m_threads.begin(); rhs_pos != rhs_end; ++rhs_pos) {
756 if (!(*rhs_pos)->IsValid())
760 bool thread_is_alive =
false;
761 const uint32_t num_threads =
m_threads.size();
762 for (uint32_t idx = 0; idx < num_threads; ++idx) {
765 (backing_thread && backing_thread->GetID() == tid)) {
766 thread_is_alive =
true;
770 if (!thread_is_alive) {
771 (*rhs_pos)->DestroyThread();
778 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
779 collection::iterator pos, end =
m_threads.end();
780 for (pos =
m_threads.begin(); pos != end; ++pos)
792 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)
void DiscardThreadPlans()
void RefreshStateAfterStop()
void Update(ThreadList &rhs)
lldb::ThreadSP GetBackingThread(const lldb::ThreadSP &real_thread)
Process * m_process
The process that manages this thread list.
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)
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...