1254721Semaste//===-- ThreadList.h --------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_ThreadList_h_ 11254721Semaste#define liblldb_ThreadList_h_ 12254721Semaste 13254721Semaste#include <vector> 14254721Semaste 15254721Semaste#include "lldb/lldb-private.h" 16254721Semaste#include "lldb/Core/UserID.h" 17263367Semaste#include "lldb/Utility/Iterable.h" 18254721Semaste 19254721Semaste 20254721Semaste// FIXME: Currently this is a thread list with lots of functionality for use only by 21254721Semaste// the process for which this is the thread list. If we ever want a container class 22254721Semaste// to hand out that is just a random subset of threads, with iterator functionality, 23254721Semaste// then we should make that part a base class, and make a ProcessThreadList for the 24254721Semaste// process. 25254721Semastenamespace lldb_private { 26254721Semaste 27254721Semasteclass ThreadList 28254721Semaste{ 29254721Semastefriend class Process; 30254721Semaste 31254721Semastepublic: 32254721Semaste 33254721Semaste ThreadList (Process *process); 34254721Semaste 35254721Semaste ThreadList (const ThreadList &rhs); 36254721Semaste 37254721Semaste ~ThreadList (); 38254721Semaste 39254721Semaste const ThreadList& 40254721Semaste operator = (const ThreadList& rhs); 41254721Semaste 42254721Semaste uint32_t 43254721Semaste GetSize(bool can_update = true); 44254721Semaste 45254721Semaste void 46254721Semaste AddThread (const lldb::ThreadSP &thread_sp); 47254721Semaste 48269024Semaste void 49269024Semaste InsertThread (const lldb::ThreadSP &thread_sp, uint32_t idx); 50254721Semaste // Return the selected thread if there is one. Otherwise, return the thread 51254721Semaste // selected at index 0. 52254721Semaste lldb::ThreadSP 53254721Semaste GetSelectedThread (); 54254721Semaste 55254721Semaste bool 56254721Semaste SetSelectedThreadByID (lldb::tid_t tid, bool notify = false); 57254721Semaste 58254721Semaste bool 59254721Semaste SetSelectedThreadByIndexID (uint32_t index_id, bool notify = false); 60254721Semaste 61254721Semaste void 62254721Semaste Clear(); 63254721Semaste 64254721Semaste void 65254721Semaste Flush(); 66254721Semaste 67254721Semaste void 68254721Semaste Destroy(); 69254721Semaste 70254721Semaste // Note that "idx" is not the same as the "thread_index". It is a zero 71254721Semaste // based index to accessing the current threads, whereas "thread_index" 72254721Semaste // is a unique index assigned 73254721Semaste lldb::ThreadSP 74254721Semaste GetThreadAtIndex (uint32_t idx, bool can_update = true); 75263367Semaste 76263367Semaste typedef std::vector<lldb::ThreadSP> collection; 77263367Semaste typedef LockingAdaptedIterable<collection, lldb::ThreadSP, vector_adapter> ThreadIterable; 78263367Semaste 79263367Semaste ThreadIterable 80263367Semaste Threads () 81263367Semaste { 82263367Semaste return ThreadIterable(m_threads, GetMutex()); 83263367Semaste } 84254721Semaste 85254721Semaste lldb::ThreadSP 86254721Semaste FindThreadByID (lldb::tid_t tid, bool can_update = true); 87254721Semaste 88254721Semaste lldb::ThreadSP 89254721Semaste FindThreadByProtocolID (lldb::tid_t tid, bool can_update = true); 90254721Semaste 91254721Semaste lldb::ThreadSP 92254721Semaste RemoveThreadByID (lldb::tid_t tid, bool can_update = true); 93254721Semaste 94254721Semaste lldb::ThreadSP 95254721Semaste RemoveThreadByProtocolID (lldb::tid_t tid, bool can_update = true); 96254721Semaste 97254721Semaste lldb::ThreadSP 98254721Semaste FindThreadByIndexID (uint32_t index_id, bool can_update = true); 99254721Semaste 100254721Semaste lldb::ThreadSP 101254721Semaste GetThreadSPForThreadPtr (Thread *thread_ptr); 102254721Semaste 103254721Semaste bool 104254721Semaste ShouldStop (Event *event_ptr); 105254721Semaste 106254721Semaste Vote 107254721Semaste ShouldReportStop (Event *event_ptr); 108254721Semaste 109254721Semaste Vote 110254721Semaste ShouldReportRun (Event *event_ptr); 111254721Semaste 112254721Semaste void 113254721Semaste RefreshStateAfterStop (); 114254721Semaste 115254721Semaste //------------------------------------------------------------------ 116254721Semaste /// The thread list asks tells all the threads it is about to resume. 117254721Semaste /// If a thread can "resume" without having to resume the target, it 118254721Semaste /// will return false for WillResume, and then the process will not be 119254721Semaste /// restarted. 120254721Semaste /// 121254721Semaste /// @return 122254721Semaste /// \b true instructs the process to resume normally, 123254721Semaste /// \b false means start & stopped events will be generated, but 124254721Semaste /// the process will not actually run. The thread must then return 125254721Semaste /// the correct StopInfo when asked. 126254721Semaste /// 127254721Semaste //------------------------------------------------------------------ 128254721Semaste bool 129254721Semaste WillResume (); 130254721Semaste 131254721Semaste void 132254721Semaste DidResume (); 133254721Semaste 134254721Semaste void 135254721Semaste DidStop (); 136254721Semaste 137254721Semaste void 138254721Semaste DiscardThreadPlans(); 139254721Semaste 140254721Semaste uint32_t 141254721Semaste GetStopID () const; 142254721Semaste 143254721Semaste void 144254721Semaste SetStopID (uint32_t stop_id); 145254721Semaste 146254721Semaste Mutex & 147254721Semaste GetMutex (); 148254721Semaste 149254721Semaste void 150254721Semaste Update (ThreadList &rhs); 151254721Semaste 152254721Semasteprotected: 153254721Semaste 154254721Semaste void 155254721Semaste SetShouldReportStop (Vote vote); 156254721Semaste 157254721Semaste void 158254721Semaste NotifySelectedThreadChanged (lldb::tid_t tid); 159254721Semaste 160254721Semaste //------------------------------------------------------------------ 161254721Semaste // Classes that inherit from Process can see and modify these 162254721Semaste //------------------------------------------------------------------ 163254721Semaste Process *m_process; ///< The process that manages this thread list. 164254721Semaste uint32_t m_stop_id; ///< The process stop ID that this thread list is valid for. 165254721Semaste collection m_threads; ///< The threads for this process. 166254721Semaste lldb::tid_t m_selected_tid; ///< For targets that need the notion of a current thread. 167254721Semaste 168254721Semasteprivate: 169254721Semaste ThreadList (); 170254721Semaste}; 171254721Semaste 172254721Semaste} // namespace lldb_private 173254721Semaste 174254721Semaste#endif // liblldb_ThreadList_h_ 175