ThreadList.h revision 85e3c2f2f7e60a772f9fffa3fc42d46e493d198c
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. 24namespace lldb_private { 25 26class ThreadList 27{ 28friend class Process; 29 30public: 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 DiscardThreadPlans(); 124 125 uint32_t 126 GetStopID () const; 127 128 void 129 SetStopID (uint32_t stop_id); 130 131 Mutex & 132 GetMutex (); 133 134 void 135 Update (ThreadList &rhs); 136 137protected: 138 139 void 140 SetShouldReportStop (Vote vote); 141 142 void 143 NotifySelectedThreadChanged (lldb::tid_t tid); 144 145 typedef std::vector<lldb::ThreadSP> collection; 146 //------------------------------------------------------------------ 147 // Classes that inherit from Process can see and modify these 148 //------------------------------------------------------------------ 149 Process *m_process; ///< The process that manages this thread list. 150 uint32_t m_stop_id; ///< The process stop ID that this thread list is valid for. 151 collection m_threads; ///< The threads for this process. 152 lldb::tid_t m_selected_tid; ///< For targets that need the notion of a current thread. 153 154private: 155 ThreadList (); 156}; 157 158} // namespace lldb_private 159 160#endif // liblldb_ThreadList_h_ 161