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