]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/ThreadList.h
Import Intel Processor Trace decoder library from
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / ThreadList.h
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 <mutex>
14 #include <vector>
15
16 #include "lldb/Target/Thread.h"
17 #include "lldb/Target/ThreadCollection.h"
18 #include "lldb/Utility/Iterable.h"
19 #include "lldb/Utility/UserID.h"
20 #include "lldb/lldb-private.h"
21
22 namespace lldb_private {
23
24 // This is a thread list with lots of functionality for use only by the process
25 // for which this is the thread list.  A generic container class with iterator
26 // functionality is ThreadCollection.
27 class ThreadList : public ThreadCollection {
28   friend class Process;
29
30 public:
31   ThreadList(Process *process);
32
33   ThreadList(const ThreadList &rhs);
34
35   ~ThreadList() override;
36
37   const ThreadList &operator=(const ThreadList &rhs);
38
39   uint32_t GetSize(bool can_update = true);
40
41   // Return the selected thread if there is one.  Otherwise, return the thread
42   // selected at index 0.
43   lldb::ThreadSP GetSelectedThread();
44
45   // Manage the thread to use for running expressions.  This is usually the
46   // Selected thread,
47   // but sometimes (e.g. when evaluating breakpoint conditions & stop hooks) it
48   // isn't.
49   class ExpressionExecutionThreadPusher {
50   public:
51     ExpressionExecutionThreadPusher(ThreadList &thread_list, lldb::tid_t tid)
52         : m_thread_list(&thread_list), m_tid(tid) {
53       m_thread_list->PushExpressionExecutionThread(m_tid);
54     }
55
56     ExpressionExecutionThreadPusher(lldb::ThreadSP thread_sp);
57
58     ~ExpressionExecutionThreadPusher() {
59       if (m_thread_list && m_tid != LLDB_INVALID_THREAD_ID)
60         m_thread_list->PopExpressionExecutionThread(m_tid);
61     }
62
63   private:
64     ThreadList *m_thread_list;
65     lldb::tid_t m_tid;
66   };
67
68   lldb::ThreadSP GetExpressionExecutionThread();
69
70 protected:
71   void PushExpressionExecutionThread(lldb::tid_t tid);
72
73   void PopExpressionExecutionThread(lldb::tid_t tid);
74
75 public:
76   bool SetSelectedThreadByID(lldb::tid_t tid, bool notify = false);
77
78   bool SetSelectedThreadByIndexID(uint32_t index_id, bool notify = false);
79
80   void Clear();
81
82   void Flush();
83
84   void Destroy();
85
86   // Note that "idx" is not the same as the "thread_index". It is a zero
87   // based index to accessing the current threads, whereas "thread_index"
88   // is a unique index assigned
89   lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update = true);
90
91   lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update = true);
92
93   lldb::ThreadSP FindThreadByProtocolID(lldb::tid_t tid,
94                                         bool can_update = true);
95
96   lldb::ThreadSP RemoveThreadByID(lldb::tid_t tid, bool can_update = true);
97
98   lldb::ThreadSP RemoveThreadByProtocolID(lldb::tid_t tid,
99                                           bool can_update = true);
100
101   lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update = true);
102
103   lldb::ThreadSP GetThreadSPForThreadPtr(Thread *thread_ptr);
104
105   bool ShouldStop(Event *event_ptr);
106
107   Vote ShouldReportStop(Event *event_ptr);
108
109   Vote ShouldReportRun(Event *event_ptr);
110
111   void RefreshStateAfterStop();
112
113   //------------------------------------------------------------------
114   /// The thread list asks tells all the threads it is about to resume.
115   /// If a thread can "resume" without having to resume the target, it
116   /// will return false for WillResume, and then the process will not be
117   /// restarted.
118   ///
119   /// @return
120   ///    \b true instructs the process to resume normally,
121   ///    \b false means start & stopped events will be generated, but
122   ///    the process will not actually run.  The thread must then return
123   ///    the correct StopInfo when asked.
124   ///
125   //------------------------------------------------------------------
126   bool WillResume();
127
128   void DidResume();
129
130   void DidStop();
131
132   void DiscardThreadPlans();
133
134   uint32_t GetStopID() const;
135
136   void SetStopID(uint32_t stop_id);
137
138   std::recursive_mutex &GetMutex() const override;
139
140   void Update(ThreadList &rhs);
141
142 protected:
143   void SetShouldReportStop(Vote vote);
144
145   void NotifySelectedThreadChanged(lldb::tid_t tid);
146
147   //------------------------------------------------------------------
148   // Classes that inherit from Process can see and modify these
149   //------------------------------------------------------------------
150   Process *m_process; ///< The process that manages this thread list.
151   uint32_t
152       m_stop_id; ///< The process stop ID that this thread list is valid for.
153   lldb::tid_t
154       m_selected_tid; ///< For targets that need the notion of a current thread.
155   std::vector<lldb::tid_t> m_expression_tid_stack;
156
157 private:
158   ThreadList();
159 };
160
161 } // namespace lldb_private
162
163 #endif // liblldb_ThreadList_h_