1 //===-- ThreadList.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ThreadList_h_
11 #define liblldb_ThreadList_h_
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"
22 namespace lldb_private {
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 {
31 ThreadList(Process *process);
33 ThreadList(const ThreadList &rhs);
35 ~ThreadList() override;
37 const ThreadList &operator=(const ThreadList &rhs);
39 uint32_t GetSize(bool can_update = true);
41 // Return the selected thread if there is one. Otherwise, return the thread
42 // selected at index 0.
43 lldb::ThreadSP GetSelectedThread();
45 // Manage the thread to use for running expressions. This is usually the
46 // Selected thread, but sometimes (e.g. when evaluating breakpoint conditions
47 // & stop hooks) it isn't.
48 class ExpressionExecutionThreadPusher {
50 ExpressionExecutionThreadPusher(ThreadList &thread_list, lldb::tid_t tid)
51 : m_thread_list(&thread_list), m_tid(tid) {
52 m_thread_list->PushExpressionExecutionThread(m_tid);
55 ExpressionExecutionThreadPusher(lldb::ThreadSP thread_sp);
57 ~ExpressionExecutionThreadPusher() {
58 if (m_thread_list && m_tid != LLDB_INVALID_THREAD_ID)
59 m_thread_list->PopExpressionExecutionThread(m_tid);
63 ThreadList *m_thread_list;
67 lldb::ThreadSP GetExpressionExecutionThread();
70 void PushExpressionExecutionThread(lldb::tid_t tid);
72 void PopExpressionExecutionThread(lldb::tid_t tid);
75 bool SetSelectedThreadByID(lldb::tid_t tid, bool notify = false);
77 bool SetSelectedThreadByIndexID(uint32_t index_id, bool notify = false);
85 // Note that "idx" is not the same as the "thread_index". It is a zero based
86 // index to accessing the current threads, whereas "thread_index" is a unique
88 lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update = true);
90 lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update = true);
92 lldb::ThreadSP FindThreadByProtocolID(lldb::tid_t tid,
93 bool can_update = true);
95 lldb::ThreadSP RemoveThreadByID(lldb::tid_t tid, bool can_update = true);
97 lldb::ThreadSP RemoveThreadByProtocolID(lldb::tid_t tid,
98 bool can_update = true);
100 lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update = true);
102 lldb::ThreadSP GetThreadSPForThreadPtr(Thread *thread_ptr);
104 lldb::ThreadSP GetBackingThread(const lldb::ThreadSP &real_thread);
106 bool ShouldStop(Event *event_ptr);
108 Vote ShouldReportStop(Event *event_ptr);
110 Vote ShouldReportRun(Event *event_ptr);
112 void RefreshStateAfterStop();
114 //------------------------------------------------------------------
115 /// The thread list asks tells all the threads it is about to resume.
116 /// If a thread can "resume" without having to resume the target, it
117 /// will return false for WillResume, and then the process will not be
121 /// \b true instructs the process to resume normally,
122 /// \b false means start & stopped events will be generated, but
123 /// the process will not actually run. The thread must then return
124 /// the correct StopInfo when asked.
126 //------------------------------------------------------------------
133 void DiscardThreadPlans();
135 uint32_t GetStopID() const;
137 void SetStopID(uint32_t stop_id);
139 std::recursive_mutex &GetMutex() const override;
141 void Update(ThreadList &rhs);
144 void SetShouldReportStop(Vote vote);
146 void NotifySelectedThreadChanged(lldb::tid_t tid);
148 //------------------------------------------------------------------
149 // Classes that inherit from Process can see and modify these
150 //------------------------------------------------------------------
151 Process *m_process; ///< The process that manages this thread list.
153 m_stop_id; ///< The process stop ID that this thread list is valid for.
155 m_selected_tid; ///< For targets that need the notion of a current thread.
156 std::vector<lldb::tid_t> m_expression_tid_stack;
162 } // namespace lldb_private
164 #endif // liblldb_ThreadList_h_