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());
201 const uint32_t num_threads =
m_threads.size();
202 for (uint32_t idx = 0; idx < num_threads; ++idx) {
203 if (
m_threads[idx]->GetIndexID() == index_id) {
227 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
242 thread_sp->IsStillAtLastBreakpointHit()
243 || thread_sp->ShouldRunBeforePublicStop())
244 threads_copy.push_back(thread_sp);
251 if (threads_copy.size() == 0)
255 collection::iterator pos, end = threads_copy.end();
260 "ThreadList::%s: %" PRIu64
" threads, %" PRIu64
261 " unsuspended threads",
262 __FUNCTION__, (uint64_t)
m_threads.size(),
263 (uint64_t)threads_copy.size());
266 bool did_anybody_stop_for_a_reason =
false;
270 bool should_stop =
false;
273 log,
"ThreadList::%s handling interrupt event, should stop set to true",
286 for (pos = threads_copy.begin(); pos != end; ++pos) {
288 thread_sp->GetStopInfo();
294 bool a_thread_needs_to_run =
false;
295 for (pos = threads_copy.begin(); pos != end; ++pos) {
318 if (thread_sp->GetProcess()->GetStopID() > 1)
319 did_anybody_stop_for_a_reason =
true;
321 did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
323 const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
325 if (thread_should_stop)
328 bool this_thread_forces_run = thread_sp->ShouldRunBeforePublicStop();
329 a_thread_needs_to_run |= this_thread_forces_run;
330 if (this_thread_forces_run)
332 "ThreadList::{0} thread: {1:x}, "
333 "says it needs to run before public stop.",
334 __FUNCTION__, thread_sp->GetID());
338 if (a_thread_needs_to_run) {
340 }
else if (!should_stop && !did_anybody_stop_for_a_reason) {
343 "ThreadList::%s we stopped but no threads had a stop reason, "
344 "overriding should_stop and stopping.",
348 LLDB_LOGF(log,
"ThreadList::%s overall should_stop = %i", __FUNCTION__,
352 for (pos = threads_copy.begin(); pos != end; ++pos) {
354 thread_sp->WillStop();
362 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
366 collection::iterator pos, end =
m_threads.end();
370 LLDB_LOGF(log,
"ThreadList::%s %" PRIu64
" threads", __FUNCTION__,
377 for (pos =
m_threads.begin(); pos != end; ++pos) {
379 if (thread_sp->ShouldRunBeforePublicStop()) {
380 LLDB_LOG(log,
"Thread {0:x} has private business to complete, overrode "
381 "the should report stop.", thread_sp->GetID());
386 const Vote vote = thread_sp->ShouldReportStop(event_ptr);
400 "Thread {0:x} voted {1}, but lost out because result was {2}",
401 thread_sp->GetID(), vote, result);
406 LLDB_LOG(log,
"Returning {0}", result);
411 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
414 collection::iterator pos, end =
m_threads.end();
415 for (pos =
m_threads.begin(); pos != end; ++pos) {
417 thread_sp->SetShouldReportStop(vote);
423 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
427 collection::iterator pos, end =
m_threads.end();
434 for (pos =
m_threads.begin(); pos != end; ++pos) {
436 switch ((*pos)->ShouldReportRun(event_ptr)) {
445 "ThreadList::ShouldReportRun() thread %d (0x%4.4" PRIx64
446 ") says don't report.",
447 (*pos)->GetIndexID(), (*pos)->GetID());
457 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
464 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
465 const uint32_t num_threads =
m_threads.size();
466 for (uint32_t idx = 0; idx < num_threads; ++idx) {
472 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
479 "Turning off notification of new threads while single stepping "
482 collection::iterator pos, end =
m_threads.end();
483 for (pos =
m_threads.begin(); pos != end; ++pos)
484 (*pos)->RefreshStateAfterStop();
490 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
492 collection::iterator pos, end =
m_threads.end();
493 for (pos =
m_threads.begin(); pos != end; ++pos)
494 (*pos)->DiscardThreadPlans(
true);
502 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
505 collection::iterator pos, end =
m_threads.end();
521 for (pos =
m_threads.begin(); pos != end; ++pos) {
524 thread_sp->GetCurrentPlan()->StopOthers()) {
525 if (thread_sp->IsOperatingSystemPluginThread() &&
526 !thread_sp->GetBackingThread())
534 thread_to_run = thread_sp;
536 if (thread_sp->ShouldRunBeforePublicStop()) {
538 thread_to_run = thread_sp;
544 if (run_me_only_list.
GetSize(
false) > 0 && !thread_to_run) {
545 if (run_me_only_list.
GetSize(
false) == 1) {
549 (int)((run_me_only_list.
GetSize(
false) * (
double)rand()) /
555 if (thread_to_run !=
nullptr) {
556 direction = thread_to_run->GetCurrentPlan()->GetDirection();
558 direction =
m_process.GetBaseDirection();
565 if (thread_to_run !=
nullptr) {
572 if (thread_to_run->SetupToStepOverBreakpointIfNeeded(direction)) {
576 assert(thread_to_run->GetCurrentPlan()->GetDirection() == direction);
579 for (pos =
m_threads.begin(); pos != end; ++pos) {
582 if (thread_sp->IsOperatingSystemPluginThread() &&
583 !thread_sp->GetBackingThread())
585 if (thread_sp->SetupToStepOverBreakpointIfNeeded(direction)) {
589 assert(thread_sp->GetCurrentPlan()->GetDirection() == direction);
592 thread_to_run = thread_sp;
593 if (thread_sp->ShouldRunBeforePublicStop()) {
602 if (thread_to_run !=
nullptr) {
605 LLDB_LOGF(log,
"Turning on notification of new threads while single "
606 "stepping a thread.");
611 LLDB_LOGF(log,
"Turning off notification of new threads while single "
612 "stepping a thread.");
616 bool need_to_resume =
true;
618 if (thread_to_run ==
nullptr) {
620 for (pos =
m_threads.begin(); pos != end; ++pos) {
624 run_state = thread_sp->GetCurrentPlan()->RunState();
627 if (!thread_sp->ShouldResume(run_state))
628 need_to_resume =
false;
630 if (need_to_resume) {
632 for (pos =
m_threads.begin(); pos != end; ++pos) {
634 while (thread_sp->GetCurrentPlan()->GetDirection() != direction) {
637 thread_sp->DiscardPlan();
642 for (pos =
m_threads.begin(); pos != end; ++pos) {
644 if (thread_sp == thread_to_run) {
648 if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
649 need_to_resume =
false;
655 return need_to_resume;
659 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
660 collection::iterator pos, end =
m_threads.end();
661 for (pos =
m_threads.begin(); pos != end; ++pos) {
666 thread_sp->DidResume();
671 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
672 collection::iterator pos, end =
m_threads.end();
673 for (pos =
m_threads.begin(); pos != end; ++pos) {
683 thread_sp->DidStop();
688 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
690 if (!thread_sp.get()) {
700 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
702 if (selected_thread_sp) {
704 selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
715 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
717 if (selected_thread_sp.get()) {
719 selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
731 if (selected_thread_sp->EventTypeHasListeners(
734 std::make_shared<Thread::ThreadEventData>(selected_thread_sp);
747 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
759 collection::iterator rhs_pos, rhs_end = rhs.
m_threads.end();
760 for (rhs_pos = rhs.
m_threads.begin(); rhs_pos != rhs_end; ++rhs_pos) {
763 if (!(*rhs_pos)->IsValid())
767 bool thread_is_alive =
false;
768 const uint32_t num_threads =
m_threads.size();
769 for (uint32_t idx = 0; idx < num_threads; ++idx) {
772 (backing_thread && backing_thread->GetID() == tid)) {
773 thread_is_alive =
true;
777 if (!thread_is_alive) {
778 (*rhs_pos)->DestroyThread();
785 std::lock_guard<std::recursive_mutex> guard(
GetMutex());
786 collection::iterator pos, end =
m_threads.end();
787 for (pos =
m_threads.begin(); pos != end; ++pos)
799 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)
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 WillResume(lldb::RunDirection &direction)
The thread list asks tells all the threads it is about to resume.
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.
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)
ThreadList(Process &process)
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.
RunDirection
Execution directions.
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...