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