LLDB  mainline
ThreadList.cpp
Go to the documentation of this file.
1 //===-- ThreadList.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <cstdlib>
10 
11 #include <algorithm>
12 
13 #include "lldb/Target/Process.h"
15 #include "lldb/Target/Thread.h"
16 #include "lldb/Target/ThreadList.h"
17 #include "lldb/Target/ThreadPlan.h"
19 #include "lldb/Utility/Log.h"
20 #include "lldb/Utility/State.h"
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 
25 ThreadList::ThreadList(Process *process)
26  : ThreadCollection(), m_process(process), m_stop_id(0),
27  m_selected_tid(LLDB_INVALID_THREAD_ID) {}
28 
30  : ThreadCollection(), m_process(rhs.m_process), m_stop_id(rhs.m_stop_id),
31  m_selected_tid() {
32  // Use the assignment operator since it uses the mutex
33  *this = rhs;
34 }
35 
37  if (this != &rhs) {
38  // Lock both mutexes to make sure neither side changes anyone on us while
39  // the assignment occurs
40  std::lock(GetMutex(), rhs.GetMutex());
41  std::lock_guard<std::recursive_mutex> guard(GetMutex(), std::adopt_lock);
42  std::lock_guard<std::recursive_mutex> rhs_guard(rhs.GetMutex(),
43  std::adopt_lock);
44 
45  m_process = rhs.m_process;
46  m_stop_id = rhs.m_stop_id;
47  m_threads = rhs.m_threads;
49  }
50  return *this;
51 }
52 
54  // Clear the thread list. Clear will take the mutex lock which will ensure
55  // that if anyone is using the list they won't get it removed while using it.
56  Clear();
57 }
58 
60  if (m_expression_tid_stack.empty())
61  return GetSelectedThread();
62  ThreadSP expr_thread_sp = FindThreadByID(m_expression_tid_stack.back());
63  if (expr_thread_sp)
64  return expr_thread_sp;
65  else
66  return GetSelectedThread();
67 }
68 
70  m_expression_tid_stack.push_back(tid);
71 }
72 
74  assert(m_expression_tid_stack.back() == tid);
75  m_expression_tid_stack.pop_back();
76 }
77 
79 
80 void ThreadList::SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
81 
82 uint32_t ThreadList::GetSize(bool can_update) {
83  std::lock_guard<std::recursive_mutex> guard(GetMutex());
84 
85  if (can_update)
87  return m_threads.size();
88 }
89 
90 ThreadSP ThreadList::GetThreadAtIndex(uint32_t idx, bool can_update) {
91  std::lock_guard<std::recursive_mutex> guard(GetMutex());
92 
93  if (can_update)
95 
96  ThreadSP thread_sp;
97  if (idx < m_threads.size())
98  thread_sp = m_threads[idx];
99  return thread_sp;
100 }
101 
102 ThreadSP ThreadList::FindThreadByID(lldb::tid_t tid, bool can_update) {
103  std::lock_guard<std::recursive_mutex> guard(GetMutex());
104 
105  if (can_update)
107 
108  ThreadSP thread_sp;
109  uint32_t idx = 0;
110  const uint32_t num_threads = m_threads.size();
111  for (idx = 0; idx < num_threads; ++idx) {
112  if (m_threads[idx]->GetID() == tid) {
113  thread_sp = m_threads[idx];
114  break;
115  }
116  }
117  return thread_sp;
118 }
119 
120 ThreadSP ThreadList::FindThreadByProtocolID(lldb::tid_t tid, bool can_update) {
121  std::lock_guard<std::recursive_mutex> guard(GetMutex());
122 
123  if (can_update)
125 
126  ThreadSP thread_sp;
127  uint32_t idx = 0;
128  const uint32_t num_threads = m_threads.size();
129  for (idx = 0; idx < num_threads; ++idx) {
130  if (m_threads[idx]->GetProtocolID() == tid) {
131  thread_sp = m_threads[idx];
132  break;
133  }
134  }
135  return thread_sp;
136 }
137 
138 ThreadSP ThreadList::RemoveThreadByID(lldb::tid_t tid, bool can_update) {
139  std::lock_guard<std::recursive_mutex> guard(GetMutex());
140 
141  if (can_update)
143 
144  ThreadSP thread_sp;
145  uint32_t idx = 0;
146  const uint32_t num_threads = m_threads.size();
147  for (idx = 0; idx < num_threads; ++idx) {
148  if (m_threads[idx]->GetID() == tid) {
149  thread_sp = m_threads[idx];
150  m_threads.erase(m_threads.begin() + idx);
151  break;
152  }
153  }
154  return thread_sp;
155 }
156 
158  bool can_update) {
159  std::lock_guard<std::recursive_mutex> guard(GetMutex());
160 
161  if (can_update)
163 
164  ThreadSP thread_sp;
165  uint32_t idx = 0;
166  const uint32_t num_threads = m_threads.size();
167  for (idx = 0; idx < num_threads; ++idx) {
168  if (m_threads[idx]->GetProtocolID() == tid) {
169  thread_sp = m_threads[idx];
170  m_threads.erase(m_threads.begin() + idx);
171  break;
172  }
173  }
174  return thread_sp;
175 }
176 
178  ThreadSP thread_sp;
179  if (thread_ptr) {
180  std::lock_guard<std::recursive_mutex> guard(GetMutex());
181 
182  uint32_t idx = 0;
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) {
186  thread_sp = m_threads[idx];
187  break;
188  }
189  }
190  }
191  return thread_sp;
192 }
193 
194 ThreadSP ThreadList::GetBackingThread(const ThreadSP &real_thread) {
195  std::lock_guard<std::recursive_mutex> guard(GetMutex());
196 
197  ThreadSP thread_sp;
198  const uint32_t num_threads = m_threads.size();
199  for (uint32_t idx = 0; idx < num_threads; ++idx) {
200  if (m_threads[idx]->GetBackingThread() == real_thread) {
201  thread_sp = m_threads[idx];
202  break;
203  }
204  }
205  return thread_sp;
206 }
207 
208 ThreadSP ThreadList::FindThreadByIndexID(uint32_t index_id, bool can_update) {
209  std::lock_guard<std::recursive_mutex> guard(GetMutex());
210 
211  if (can_update)
213 
214  ThreadSP thread_sp;
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) {
218  thread_sp = m_threads[idx];
219  break;
220  }
221  }
222  return thread_sp;
223 }
224 
225 bool ThreadList::ShouldStop(Event *event_ptr) {
226  // Running events should never stop, obviously...
227 
229 
230  // The ShouldStop method of the threads can do a whole lot of work, figuring
231  // out whether the thread plan conditions are met. So we don't want to keep
232  // the ThreadList locked the whole time we are doing this.
233  // FIXME: It is possible that running code could cause new threads
234  // to be created. If that happens, we will miss asking them whether they
235  // should stop. This is not a big deal since we haven't had a chance to hang
236  // any interesting operations on those threads yet.
237 
238  collection threads_copy;
239  {
240  // Scope for locker
241  std::lock_guard<std::recursive_mutex> guard(GetMutex());
242 
244  for (lldb::ThreadSP thread_sp : m_threads) {
245  // This is an optimization... If we didn't let a thread run in between
246  // the previous stop and this one, we shouldn't have to consult it for
247  // ShouldStop. So just leave it off the list we are going to inspect. On
248  // Linux, if a thread-specific conditional breakpoint was hit, it won't
249  // necessarily be the thread that hit the breakpoint itself that
250  // evaluates the conditional expression, so the thread that hit the
251  // breakpoint could still be asked to stop, even though it hasn't been
252  // allowed to run since the previous stop.
253  if (thread_sp->GetTemporaryResumeState() != eStateSuspended ||
254  thread_sp->IsStillAtLastBreakpointHit())
255  threads_copy.push_back(thread_sp);
256  }
257 
258  // It is possible the threads we were allowing to run all exited and then
259  // maybe the user interrupted or something, then fall back on looking at
260  // all threads:
261 
262  if (threads_copy.size() == 0)
263  threads_copy = m_threads;
264  }
265 
266  collection::iterator pos, end = threads_copy.end();
267 
268  if (log) {
269  log->PutCString("");
270  LLDB_LOGF(log,
271  "ThreadList::%s: %" PRIu64 " threads, %" PRIu64
272  " unsuspended threads",
273  __FUNCTION__, (uint64_t)m_threads.size(),
274  (uint64_t)threads_copy.size());
275  }
276 
277  bool did_anybody_stop_for_a_reason = false;
278 
279  // If the event is an Interrupt event, then we're going to stop no matter
280  // what. Otherwise, presume we won't stop.
281  bool should_stop = false;
283  LLDB_LOGF(
284  log, "ThreadList::%s handling interrupt event, should stop set to true",
285  __FUNCTION__);
286 
287  should_stop = true;
288  }
289 
290  // Now we run through all the threads and get their stop info's. We want to
291  // make sure to do this first before we start running the ShouldStop, because
292  // one thread's ShouldStop could destroy information (like deleting a thread
293  // specific breakpoint another thread had stopped at) which could lead us to
294  // compute the StopInfo incorrectly. We don't need to use it here, we just
295  // want to make sure it gets computed.
296 
297  for (pos = threads_copy.begin(); pos != end; ++pos) {
298  ThreadSP thread_sp(*pos);
299  thread_sp->GetStopInfo();
300  }
301 
302  for (pos = threads_copy.begin(); pos != end; ++pos) {
303  ThreadSP thread_sp(*pos);
304 
305  // We should never get a stop for which no thread had a stop reason, but
306  // sometimes we do see this - for instance when we first connect to a
307  // remote stub. In that case we should stop, since we can't figure out the
308  // right thing to do and stopping gives the user control over what to do in
309  // this instance.
310  //
311  // Note, this causes a problem when you have a thread specific breakpoint,
312  // and a bunch of threads hit the breakpoint, but not the thread which we
313  // are waiting for. All the threads that are not "supposed" to hit the
314  // breakpoint are marked as having no stop reason, which is right, they
315  // should not show a stop reason. But that triggers this code and causes
316  // us to stop seemingly for no reason.
317  //
318  // Since the only way we ever saw this error was on first attach, I'm only
319  // going to trigger set did_anybody_stop_for_a_reason to true unless this
320  // is the first stop.
321  //
322  // If this becomes a problem, we'll have to have another StopReason like
323  // "StopInfoHidden" which will look invalid everywhere but at this check.
324 
325  if (thread_sp->GetProcess()->GetStopID() > 1)
326  did_anybody_stop_for_a_reason = true;
327  else
328  did_anybody_stop_for_a_reason |= thread_sp->ThreadStoppedForAReason();
329 
330  const bool thread_should_stop = thread_sp->ShouldStop(event_ptr);
331  if (thread_should_stop)
332  should_stop |= true;
333  }
334 
335  if (!should_stop && !did_anybody_stop_for_a_reason) {
336  should_stop = true;
337  LLDB_LOGF(log,
338  "ThreadList::%s we stopped but no threads had a stop reason, "
339  "overriding should_stop and stopping.",
340  __FUNCTION__);
341  }
342 
343  LLDB_LOGF(log, "ThreadList::%s overall should_stop = %i", __FUNCTION__,
344  should_stop);
345 
346  if (should_stop) {
347  for (pos = threads_copy.begin(); pos != end; ++pos) {
348  ThreadSP thread_sp(*pos);
349  thread_sp->WillStop();
350  }
351  }
352 
353  return should_stop;
354 }
355 
357  std::lock_guard<std::recursive_mutex> guard(GetMutex());
358 
359  Vote result = eVoteNoOpinion;
361  collection::iterator pos, end = m_threads.end();
362 
364 
365  LLDB_LOGF(log, "ThreadList::%s %" PRIu64 " threads", __FUNCTION__,
366  (uint64_t)m_threads.size());
367 
368  // Run through the threads and ask whether we should report this event. For
369  // stopping, a YES vote wins over everything. A NO vote wins over NO
370  // opinion.
371  for (pos = m_threads.begin(); pos != end; ++pos) {
372  ThreadSP thread_sp(*pos);
373  const Vote vote = thread_sp->ShouldReportStop(event_ptr);
374  switch (vote) {
375  case eVoteNoOpinion:
376  continue;
377 
378  case eVoteYes:
379  result = eVoteYes;
380  break;
381 
382  case eVoteNo:
383  if (result == eVoteNoOpinion) {
384  result = eVoteNo;
385  } else {
386  LLDB_LOG(log,
387  "Thread {0:x} voted {1}, but lost out because result was {2}",
388  thread_sp->GetID(), vote, result);
389  }
390  break;
391  }
392  }
393  LLDB_LOG(log, "Returning {0}", result);
394  return result;
395 }
396 
398  std::lock_guard<std::recursive_mutex> guard(GetMutex());
399 
401  collection::iterator pos, end = m_threads.end();
402  for (pos = m_threads.begin(); pos != end; ++pos) {
403  ThreadSP thread_sp(*pos);
404  thread_sp->SetShouldReportStop(vote);
405  }
406 }
407 
409 
410  std::lock_guard<std::recursive_mutex> guard(GetMutex());
411 
412  Vote result = eVoteNoOpinion;
414  collection::iterator pos, end = m_threads.end();
415 
416  // Run through the threads and ask whether we should report this event. The
417  // rule is NO vote wins over everything, a YES vote wins over no opinion.
418 
420 
421  for (pos = m_threads.begin(); pos != end; ++pos) {
422  if ((*pos)->GetResumeState() != eStateSuspended) {
423  switch ((*pos)->ShouldReportRun(event_ptr)) {
424  case eVoteNoOpinion:
425  continue;
426  case eVoteYes:
427  if (result == eVoteNoOpinion)
428  result = eVoteYes;
429  break;
430  case eVoteNo:
431  LLDB_LOGF(log,
432  "ThreadList::ShouldReportRun() thread %d (0x%4.4" PRIx64
433  ") says don't report.",
434  (*pos)->GetIndexID(), (*pos)->GetID());
435  result = eVoteNo;
436  break;
437  }
438  }
439  }
440  return result;
441 }
442 
444  std::lock_guard<std::recursive_mutex> guard(GetMutex());
445  m_stop_id = 0;
446  m_threads.clear();
448 }
449 
451  std::lock_guard<std::recursive_mutex> guard(GetMutex());
452  const uint32_t num_threads = m_threads.size();
453  for (uint32_t idx = 0; idx < num_threads; ++idx) {
454  m_threads[idx]->DestroyThread();
455  }
456 }
457 
459  std::lock_guard<std::recursive_mutex> guard(GetMutex());
460 
462 
464  if (log && log->GetVerbose())
465  LLDB_LOGF(log,
466  "Turning off notification of new threads while single stepping "
467  "a thread.");
468 
469  collection::iterator pos, end = m_threads.end();
470  for (pos = m_threads.begin(); pos != end; ++pos)
471  (*pos)->RefreshStateAfterStop();
472 }
473 
475  // You don't need to update the thread list here, because only threads that
476  // you currently know about have any thread plans.
477  std::lock_guard<std::recursive_mutex> guard(GetMutex());
478 
479  collection::iterator pos, end = m_threads.end();
480  for (pos = m_threads.begin(); pos != end; ++pos)
481  (*pos)->DiscardThreadPlans(true);
482 }
483 
485  // Run through the threads and perform their momentary actions. But we only
486  // do this for threads that are running, user suspended threads stay where
487  // they are.
488 
489  std::lock_guard<std::recursive_mutex> guard(GetMutex());
491 
492  collection::iterator pos, end = m_threads.end();
493 
494  // See if any thread wants to run stopping others. If it does, then we won't
495  // setup the other threads for resume, since they aren't going to get a
496  // chance to run. This is necessary because the SetupForResume might add
497  // "StopOthers" plans which would then get to be part of the who-gets-to-run
498  // negotiation, but they're coming in after the fact, and the threads that
499  // are already set up should take priority.
500 
501  bool wants_solo_run = false;
502 
503  for (pos = m_threads.begin(); pos != end; ++pos) {
504  lldbassert((*pos)->GetCurrentPlan() &&
505  "thread should not have null thread plan");
506  if ((*pos)->GetResumeState() != eStateSuspended &&
507  (*pos)->GetCurrentPlan()->StopOthers()) {
508  if ((*pos)->IsOperatingSystemPluginThread() &&
509  !(*pos)->GetBackingThread())
510  continue;
511  wants_solo_run = true;
512  break;
513  }
514  }
515 
516  if (wants_solo_run) {
518  if (log && log->GetVerbose())
519  LLDB_LOGF(log, "Turning on notification of new threads while single "
520  "stepping a thread.");
522  } else {
524  if (log && log->GetVerbose())
525  LLDB_LOGF(log, "Turning off notification of new threads while single "
526  "stepping a thread.");
528  }
529 
530  // Give all the threads that are likely to run a last chance to set up their
531  // state before we negotiate who is actually going to get a chance to run...
532  // Don't set to resume suspended threads, and if any thread wanted to stop
533  // others, only call setup on the threads that request StopOthers...
534 
535  for (pos = m_threads.begin(); pos != end; ++pos) {
536  if ((*pos)->GetResumeState() != eStateSuspended &&
537  (!wants_solo_run || (*pos)->GetCurrentPlan()->StopOthers())) {
538  if ((*pos)->IsOperatingSystemPluginThread() &&
539  !(*pos)->GetBackingThread())
540  continue;
541  (*pos)->SetupForResume();
542  }
543  }
544 
545  // Now go through the threads and see if any thread wants to run just itself.
546  // if so then pick one and run it.
547 
548  ThreadList run_me_only_list(m_process);
549 
550  run_me_only_list.SetStopID(m_process->GetStopID());
551 
552  bool run_only_current_thread = false;
553 
554  for (pos = m_threads.begin(); pos != end; ++pos) {
555  ThreadSP thread_sp(*pos);
556  if (thread_sp->GetResumeState() != eStateSuspended &&
557  thread_sp->GetCurrentPlan()->StopOthers()) {
558  if ((*pos)->IsOperatingSystemPluginThread() &&
559  !(*pos)->GetBackingThread())
560  continue;
561 
562  // You can't say "stop others" and also want yourself to be suspended.
563  assert(thread_sp->GetCurrentPlan()->RunState() != eStateSuspended);
564 
565  if (thread_sp == GetSelectedThread()) {
566  // If the currently selected thread wants to run on its own, always let
567  // it.
568  run_only_current_thread = true;
569  run_me_only_list.Clear();
570  run_me_only_list.AddThread(thread_sp);
571  break;
572  }
573 
574  run_me_only_list.AddThread(thread_sp);
575  }
576  }
577 
578  bool need_to_resume = true;
579 
580  if (run_me_only_list.GetSize(false) == 0) {
581  // Everybody runs as they wish:
582  for (pos = m_threads.begin(); pos != end; ++pos) {
583  ThreadSP thread_sp(*pos);
584  StateType run_state;
585  if (thread_sp->GetResumeState() != eStateSuspended)
586  run_state = thread_sp->GetCurrentPlan()->RunState();
587  else
588  run_state = eStateSuspended;
589  if (!thread_sp->ShouldResume(run_state))
590  need_to_resume = false;
591  }
592  } else {
593  ThreadSP thread_to_run;
594 
595  if (run_only_current_thread) {
596  thread_to_run = GetSelectedThread();
597  } else if (run_me_only_list.GetSize(false) == 1) {
598  thread_to_run = run_me_only_list.GetThreadAtIndex(0);
599  } else {
600  int random_thread =
601  (int)((run_me_only_list.GetSize(false) * (double)rand()) /
602  (RAND_MAX + 1.0));
603  thread_to_run = run_me_only_list.GetThreadAtIndex(random_thread);
604  }
605 
606  for (pos = m_threads.begin(); pos != end; ++pos) {
607  ThreadSP thread_sp(*pos);
608  if (thread_sp == thread_to_run) {
609  if (!thread_sp->ShouldResume(thread_sp->GetCurrentPlan()->RunState()))
610  need_to_resume = false;
611  } else
612  thread_sp->ShouldResume(eStateSuspended);
613  }
614  }
615 
616  return need_to_resume;
617 }
618 
620  std::lock_guard<std::recursive_mutex> guard(GetMutex());
621  collection::iterator pos, end = m_threads.end();
622  for (pos = m_threads.begin(); pos != end; ++pos) {
623  // Don't clear out threads that aren't going to get a chance to run, rather
624  // leave their state for the next time around.
625  ThreadSP thread_sp(*pos);
626  if (thread_sp->GetResumeState() != eStateSuspended)
627  thread_sp->DidResume();
628  }
629 }
630 
632  std::lock_guard<std::recursive_mutex> guard(GetMutex());
633  collection::iterator pos, end = m_threads.end();
634  for (pos = m_threads.begin(); pos != end; ++pos) {
635  // Notify threads that the process just stopped. Note, this currently
636  // assumes that all threads in the list stop when the process stops. In
637  // the future we will want to support a debugging model where some threads
638  // continue to run while others are stopped. We either need to handle that
639  // somehow here or create a special thread list containing only threads
640  // which will stop in the code that calls this method (currently
641  // Process::SetPrivateState).
642  ThreadSP thread_sp(*pos);
643  if (StateIsRunningState(thread_sp->GetState()))
644  thread_sp->DidStop();
645  }
646 }
647 
649  std::lock_guard<std::recursive_mutex> guard(GetMutex());
650  ThreadSP thread_sp = FindThreadByID(m_selected_tid);
651  if (!thread_sp.get()) {
652  if (m_threads.size() == 0)
653  return thread_sp;
654  m_selected_tid = m_threads[0]->GetID();
655  thread_sp = m_threads[0];
656  }
657  return thread_sp;
658 }
659 
661  std::lock_guard<std::recursive_mutex> guard(GetMutex());
662  ThreadSP selected_thread_sp(FindThreadByID(tid));
663  if (selected_thread_sp) {
664  m_selected_tid = tid;
665  selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
666  } else
668 
669  if (notify)
671 
673 }
674 
676  std::lock_guard<std::recursive_mutex> guard(GetMutex());
677  ThreadSP selected_thread_sp(FindThreadByIndexID(index_id));
678  if (selected_thread_sp.get()) {
679  m_selected_tid = selected_thread_sp->GetID();
680  selected_thread_sp->SetDefaultFileAndLineToSelectedFrame();
681  } else
683 
684  if (notify)
686 
688 }
689 
691  ThreadSP selected_thread_sp(FindThreadByID(tid));
692  if (selected_thread_sp->EventTypeHasListeners(
694  selected_thread_sp->BroadcastEvent(
696  new Thread::ThreadEventData(selected_thread_sp));
697 }
698 
700  if (this != &rhs) {
701  // Lock both mutexes to make sure neither side changes anyone on us while
702  // the assignment occurs
703  std::lock_guard<std::recursive_mutex> guard(GetMutex());
704 
705  m_process = rhs.m_process;
706  m_stop_id = rhs.m_stop_id;
707  m_threads.swap(rhs.m_threads);
709 
710  // Now we look for threads that we are done with and make sure to clear
711  // them up as much as possible so anyone with a shared pointer will still
712  // have a reference, but the thread won't be of much use. Using
713  // std::weak_ptr for all backward references (such as a thread to a
714  // process) will eventually solve this issue for us, but for now, we need
715  // to work around the issue
716  collection::iterator rhs_pos, rhs_end = rhs.m_threads.end();
717  for (rhs_pos = rhs.m_threads.begin(); rhs_pos != rhs_end; ++rhs_pos) {
718  // If this thread has already been destroyed, we don't need to look for
719  // it to destroy it again.
720  if (!(*rhs_pos)->IsValid())
721  continue;
722 
723  const lldb::tid_t tid = (*rhs_pos)->GetID();
724  bool thread_is_alive = false;
725  const uint32_t num_threads = m_threads.size();
726  for (uint32_t idx = 0; idx < num_threads; ++idx) {
727  ThreadSP backing_thread = m_threads[idx]->GetBackingThread();
728  if (m_threads[idx]->GetID() == tid ||
729  (backing_thread && backing_thread->GetID() == tid)) {
730  thread_is_alive = true;
731  break;
732  }
733  }
734  if (!thread_is_alive) {
735  (*rhs_pos)->DestroyThread();
736  }
737  }
738  }
739 }
740 
742  std::lock_guard<std::recursive_mutex> guard(GetMutex());
743  collection::iterator pos, end = m_threads.end();
744  for (pos = m_threads.begin(); pos != end; ++pos)
745  (*pos)->Flush();
746 }
747 
748 std::recursive_mutex &ThreadList::GetMutex() const {
749  return m_process->m_thread_mutex;
750 }
751 
753  lldb::ThreadSP thread_sp)
754  : m_thread_list(nullptr), m_tid(LLDB_INVALID_THREAD_ID) {
755  if (thread_sp) {
756  m_tid = thread_sp->GetID();
757  m_thread_list = &thread_sp->GetProcess()->GetThreadList();
759  }
760 }
lldb_private::ThreadList::ExpressionExecutionThreadPusher::ExpressionExecutionThreadPusher
ExpressionExecutionThreadPusher(ThreadList &thread_list, lldb::tid_t tid)
Definition: ThreadList.h:49
lldb_private::ThreadList::WillResume
bool WillResume()
The thread list asks tells all the threads it is about to resume.
Definition: ThreadList.cpp:484
lldb_private::ThreadList::ExpressionExecutionThreadPusher::m_tid
lldb::tid_t m_tid
Definition: ThreadList.h:63
lldb_private::Log::GetVerbose
bool GetVerbose() const
Definition: Log.cpp:276
lldb_private::ThreadList::ShouldReportRun
Vote ShouldReportRun(Event *event_ptr)
Definition: ThreadList.cpp:408
lldb_private::Event
Definition: Event.h:180
lldb_private::Process::ProcessEventData::GetInterruptedFromEvent
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition: Process.cpp:4135
lldb_private::eVoteYes
@ eVoteYes
Definition: lldb-private-enumerations.h:59
lldb_private::ThreadList::m_expression_tid_stack
std::vector< lldb::tid_t > m_expression_tid_stack
Definition: ThreadList.h:151
lldb_private::ThreadList::SetShouldReportStop
void SetShouldReportStop(Vote vote)
Definition: ThreadList.cpp:397
lldb_private::ThreadList::GetStopID
uint32_t GetStopID() const
Definition: ThreadList.cpp:78
lldb_private::ThreadList::ShouldStop
bool ShouldStop(Event *event_ptr)
Definition: ThreadList.cpp:225
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::Process
Definition: Process.h:341
lldb_private::ThreadList::m_stop_id
uint32_t m_stop_id
The process stop ID that this thread list is valid for.
Definition: ThreadList.h:148
lldb_private::ThreadCollection::GetSize
uint32_t GetSize()
Definition: ThreadCollection.cpp:54
lldb_private::ThreadList::GetBackingThread
lldb::ThreadSP GetBackingThread(const lldb::ThreadSP &real_thread)
Definition: ThreadList.cpp:194
lldb_private::Process::StopNoticingNewThreads
virtual bool StopNoticingNewThreads()
Call this to turn off the stop & notice new threads mode.
Definition: Process.h:2314
lldb_private::ThreadCollection::collection
std::vector< lldb::ThreadSP > collection
Definition: ThreadCollection.h:22
lldb_private::ThreadList::ShouldReportStop
Vote ShouldReportStop(Event *event_ptr)
Definition: ThreadList.cpp:356
lldb_private::ThreadList::RefreshStateAfterStop
void RefreshStateAfterStop()
Definition: ThreadList.cpp:458
lldb_private::StateIsRunningState
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
Definition: State.cpp:68
lldb_private::ThreadList::~ThreadList
~ThreadList() override
Definition: ThreadList.cpp:53
lldb_private::eVoteNoOpinion
@ eVoteNoOpinion
Definition: lldb-private-enumerations.h:59
Process.h
lldb_private::ThreadList::NotifySelectedThreadChanged
void NotifySelectedThreadChanged(lldb::tid_t tid)
Definition: ThreadList.cpp:690
lldb_private::Thread::ThreadEventData
Definition: Thread.h:81
lldb_private::ThreadList::Clear
void Clear()
Definition: ThreadList.cpp:443
lldb_private::ThreadList::SetSelectedThreadByID
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
Definition: ThreadList.cpp:660
lldb_private::eVoteNo
@ eVoteNo
Definition: lldb-private-enumerations.h:59
LLDBAssert.h
lldb_private::ThreadList::FindThreadByID
lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update=true)
Definition: ThreadList.cpp:102
Log.h
lldb_private::Thread
Definition: Thread.h:60
lldb_private::ThreadList
Definition: ThreadList.h:26
lldb_private::ThreadList::ExpressionExecutionThreadPusher::m_thread_list
ThreadList * m_thread_list
Definition: ThreadList.h:62
lldb_private::Process::UpdateThreadListIfNeeded
void UpdateThreadListIfNeeded()
Definition: Process.cpp:1138
lldb_private::ThreadList::GetMutex
std::recursive_mutex & GetMutex() const override
Definition: ThreadList.cpp:748
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::Process::m_thread_mutex
std::recursive_mutex m_thread_mutex
Definition: Process.h:2861
lldb_private::Process::StartNoticingNewThreads
virtual bool StartNoticingNewThreads()
Call this to set the lldb in the mode where it breaks on new thread creations, and then auto-restarts...
Definition: Process.h:2307
ThreadList.h
lldb_private::ThreadList::GetThreadAtIndex
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:90
lldb_private::ThreadList::FindThreadByProtocolID
lldb::ThreadSP FindThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
Definition: ThreadList.cpp:120
Thread.h
lldb_private::ThreadList::RemoveThreadByID
lldb::ThreadSP RemoveThreadByID(lldb::tid_t tid, bool can_update=true)
Definition: ThreadList.cpp:138
ThreadPlan.h
lldb_private::ThreadList::SetSelectedThreadByIndexID
bool SetSelectedThreadByIndexID(uint32_t index_id, bool notify=false)
Definition: ThreadList.cpp:675
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb::eStateSuspended
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
Definition: lldb-enumerations.h:91
lldb_private::ThreadList::m_selected_tid
lldb::tid_t m_selected_tid
For targets that need the notion of a current thread.
Definition: ThreadList.h:150
uint32_t
lldb_private::ThreadList::Destroy
void Destroy()
Definition: ThreadList.cpp:450
lldb_private::ThreadList::GetThreadSPForThreadPtr
lldb::ThreadSP GetThreadSPForThreadPtr(Thread *thread_ptr)
Definition: ThreadList.cpp:177
lldb_private::ThreadList::Update
void Update(ThreadList &rhs)
Definition: ThreadList.cpp:699
lldb_private::ThreadList::SetStopID
void SetStopID(uint32_t stop_id)
Definition: ThreadList.cpp:80
lldb_private::ThreadList::GetSize
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:82
lldb_private::ThreadList::m_process
Process * m_process
The process that manages this thread list.
Definition: ThreadList.h:146
lldb_private::ThreadList::Flush
void Flush()
Definition: ThreadList.cpp:741
lldb_private::ThreadList::DiscardThreadPlans
void DiscardThreadPlans()
Definition: ThreadList.cpp:474
lldb_private::Vote
Vote
Definition: lldb-private-enumerations.h:59
lldb_private::ThreadList::DidResume
void DidResume()
Definition: ThreadList.cpp:619
lldb_private::Thread::eBroadcastBitThreadSelected
@ eBroadcastBitThreadSelected
Definition: Thread.h:72
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::ThreadList::ThreadList
ThreadList()=delete
lldb_private::ThreadCollection
Definition: ThreadCollection.h:20
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LIBLLDB_LOG_STEP
#define LIBLLDB_LOG_STEP
Definition: Logging.h:21
lldb_private::ThreadList::FindThreadByIndexID
lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update=true)
Definition: ThreadList.cpp:208
lldb_private::ThreadList::RemoveThreadByProtocolID
lldb::ThreadSP RemoveThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
Definition: ThreadList.cpp:157
lldb_private::ThreadList::DidStop
void DidStop()
Definition: ThreadList.cpp:631
State.h
lldb_private::ThreadCollection::AddThread
void AddThread(const lldb::ThreadSP &thread_sp)
Definition: ThreadCollection.cpp:24
lldb_private::ThreadList::operator=
const ThreadList & operator=(const ThreadList &rhs)
Definition: ThreadList.cpp:36
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:94
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb_private::Log
Definition: Log.h:49
lldb_private::ThreadList::PopExpressionExecutionThread
void PopExpressionExecutionThread(lldb::tid_t tid)
Definition: ThreadList.cpp:73
lldb_private::Process::GetStopID
uint32_t GetStopID() const
Definition: Process.h:1368
lldb_private::ThreadList::GetSelectedThread
lldb::ThreadSP GetSelectedThread()
Definition: ThreadList.cpp:648
lldb_private::ThreadCollection::m_threads
collection m_threads
Definition: ThreadCollection.h:53
lldb_private::ThreadList::PushExpressionExecutionThread
void PushExpressionExecutionThread(lldb::tid_t tid)
Definition: ThreadList.cpp:69
lldb
Definition: SBAddress.h:15
lldb_private::ThreadList::GetExpressionExecutionThread
lldb::ThreadSP GetExpressionExecutionThread()
Definition: ThreadList.cpp:59
RegisterContext.h
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::Log::PutCString
void PutCString(const char *cstr)
Definition: Log.cpp:118