1 //===-- ThreadList.h --------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_ThreadList_h_ 11 #define liblldb_ThreadList_h_ 12 13 #include <vector> 14 15 #include "lldb/lldb-private.h" 16 #include "lldb/Core/UserID.h" 17 18 19 // FIXME: Currently this is a thread list with lots of functionality for use only by 20 // the process for which this is the thread list. If we ever want a container class 21 // to hand out that is just a random subset of threads, with iterator functionality, 22 // then we should make that part a base class, and make a ProcessThreadList for the 23 // process. 24 namespace lldb_private { 25 26 class ThreadList 27 { 28 friend class Process; 29 30 public: 31 32 ThreadList (Process *process); 33 34 ThreadList (const ThreadList &rhs); 35 36 ~ThreadList (); 37 38 const ThreadList& 39 operator = (const ThreadList& rhs); 40 41 uint32_t 42 GetSize(bool can_update = true); 43 44 void 45 AddThread (const lldb::ThreadSP &thread_sp); 46 47 // Return the selected thread if there is one. Otherwise, return the thread 48 // selected at index 0. 49 lldb::ThreadSP 50 GetSelectedThread (); 51 52 bool 53 SetSelectedThreadByID (lldb::tid_t tid, bool notify = false); 54 55 bool 56 SetSelectedThreadByIndexID (uint32_t index_id, bool notify = false); 57 58 void 59 Clear(); 60 61 void 62 Flush(); 63 64 void 65 Destroy(); 66 67 // Note that "idx" is not the same as the "thread_index". It is a zero 68 // based index to accessing the current threads, whereas "thread_index" 69 // is a unique index assigned 70 lldb::ThreadSP 71 GetThreadAtIndex (uint32_t idx, bool can_update = true); 72 73 lldb::ThreadSP 74 FindThreadByID (lldb::tid_t tid, bool can_update = true); 75 76 lldb::ThreadSP 77 FindThreadByProtocolID (lldb::tid_t tid, bool can_update = true); 78 79 lldb::ThreadSP 80 RemoveThreadByID (lldb::tid_t tid, bool can_update = true); 81 82 lldb::ThreadSP 83 RemoveThreadByProtocolID (lldb::tid_t tid, bool can_update = true); 84 85 lldb::ThreadSP 86 FindThreadByIndexID (uint32_t index_id, bool can_update = true); 87 88 lldb::ThreadSP 89 GetThreadSPForThreadPtr (Thread *thread_ptr); 90 91 bool 92 ShouldStop (Event *event_ptr); 93 94 Vote 95 ShouldReportStop (Event *event_ptr); 96 97 Vote 98 ShouldReportRun (Event *event_ptr); 99 100 void 101 RefreshStateAfterStop (); 102 103 //------------------------------------------------------------------ 104 /// The thread list asks tells all the threads it is about to resume. 105 /// If a thread can "resume" without having to resume the target, it 106 /// will return false for WillResume, and then the process will not be 107 /// restarted. 108 /// 109 /// @return 110 /// \b true instructs the process to resume normally, 111 /// \b false means start & stopped events will be generated, but 112 /// the process will not actually run. The thread must then return 113 /// the correct StopInfo when asked. 114 /// 115 //------------------------------------------------------------------ 116 bool 117 WillResume (); 118 119 void 120 DidResume (); 121 122 void 123 DidStop (); 124 125 void 126 DiscardThreadPlans(); 127 128 uint32_t 129 GetStopID () const; 130 131 void 132 SetStopID (uint32_t stop_id); 133 134 Mutex & 135 GetMutex (); 136 137 void 138 Update (ThreadList &rhs); 139 140 protected: 141 142 void 143 SetShouldReportStop (Vote vote); 144 145 void 146 NotifySelectedThreadChanged (lldb::tid_t tid); 147 148 typedef std::vector<lldb::ThreadSP> collection; 149 //------------------------------------------------------------------ 150 // Classes that inherit from Process can see and modify these 151 //------------------------------------------------------------------ 152 Process *m_process; ///< The process that manages this thread list. 153 uint32_t m_stop_id; ///< The process stop ID that this thread list is valid for. 154 collection m_threads; ///< The threads for this process. 155 lldb::tid_t m_selected_tid; ///< For targets that need the notion of a current thread. 156 157 private: 158 ThreadList (); 159 }; 160 161 } // namespace lldb_private 162 163 #endif // liblldb_ThreadList_h_ 164