LLDB mainline
ThreadList.h
Go to the documentation of this file.
1//===-- ThreadList.h --------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_TARGET_THREADLIST_H
10#define LLDB_TARGET_THREADLIST_H
11
12#include <mutex>
13#include <vector>
14
15#include "lldb/Target/Thread.h"
18#include "lldb/Utility/UserID.h"
19#include "lldb/lldb-private.h"
20
21namespace lldb_private {
22
23// This is a thread list with lots of functionality for use only by the process
24// for which this is the thread list. A generic container class with iterator
25// functionality is ThreadCollection.
27 friend class Process;
28
29public:
30 ThreadList(Process &process);
31
32 ThreadList(const ThreadList &rhs);
33
34 ~ThreadList() override;
35
36 /// Precondition: both thread lists must be belong to the same process.
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.
44
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.
49 public:
51 : m_thread_list(&thread_list), m_tid(tid) {
52 m_thread_list->PushExpressionExecutionThread(m_tid);
53 }
54
56
59 m_thread_list->PopExpressionExecutionThread(m_tid);
60 }
61
62 private:
65 };
66
68
69protected:
71
73
74public:
75 bool SetSelectedThreadByID(lldb::tid_t tid, bool notify = false);
76
77 bool SetSelectedThreadByIndexID(uint32_t index_id, bool notify = false);
78
79 void Clear();
80
81 void Flush();
82
83 void Destroy();
84
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
87 // index assigned
88 lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update = true);
89
90 lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update = true);
91
93 bool can_update = true);
94
95 lldb::ThreadSP RemoveThreadByID(lldb::tid_t tid, bool can_update = true);
96
98 bool can_update = true);
99
100 lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update = true);
101
103
104 bool ShouldStop(Event *event_ptr);
105
106 Vote ShouldReportStop(Event *event_ptr);
107
108 Vote ShouldReportRun(Event *event_ptr);
109
111
112 /// The thread list asks tells all the threads it is about to resume.
113 /// If a thread can "resume" without having to resume the target, it
114 /// will return false for WillResume, and then the process will not be
115 /// restarted.
116 /// Sets *direction to the run direction of the thread(s) that will
117 /// be resumed. If threads that we want to run disagree about the
118 /// direction, we execute forwards and pop any of the thread plans
119 /// that requested reverse execution.
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 bool WillResume(lldb::RunDirection &direction);
128
129 void DidResume();
130
131 void DidStop();
132
133 void DiscardThreadPlans();
134
135 uint32_t GetStopID() const;
136
137 void SetStopID(uint32_t stop_id);
138
139 std::recursive_mutex &GetMutex() const override;
140
141 /// Precondition: both thread lists must be belong to the same process.
142 void Update(ThreadList &rhs);
143
144protected:
145 void SetShouldReportStop(Vote vote);
146
148
149 // Classes that inherit from Process can see and modify these
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.
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
157private:
158 ThreadList() = delete;
159};
160
161} // namespace lldb_private
162
163#endif // LLDB_TARGET_THREADLIST_H
ExpressionExecutionThreadPusher(ThreadList &thread_list, lldb::tid_t tid)
Definition ThreadList.h:50
lldb::ThreadSP RemoveThreadByID(lldb::tid_t tid, bool can_update=true)
lldb::ThreadSP GetSelectedThread()
bool ShouldStop(Event *event_ptr)
Vote ShouldReportStop(Event *event_ptr)
uint32_t GetStopID() const
bool SetSelectedThreadByIndexID(uint32_t index_id, bool notify=false)
lldb::ThreadSP FindThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
void PopExpressionExecutionThread(lldb::tid_t tid)
bool WillResume(lldb::RunDirection &direction)
The thread list asks tells all the threads it is about to resume.
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update=true)
Vote ShouldReportRun(Event *event_ptr)
void SetStopID(uint32_t stop_id)
lldb::ThreadSP GetThreadSPForThreadPtr(Thread *thread_ptr)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
uint32_t m_stop_id
The process stop ID that this thread list is valid for.
Definition ThreadList.h:152
std::recursive_mutex & GetMutex() const override
lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update=true)
lldb::ThreadSP GetExpressionExecutionThread()
const ThreadList & operator=(const ThreadList &rhs)
Precondition: both thread lists must be belong to the same process.
void Update(ThreadList &rhs)
Precondition: both thread lists must be belong to the same process.
void PushExpressionExecutionThread(lldb::tid_t tid)
void SetShouldReportStop(Vote vote)
lldb::tid_t m_selected_tid
For targets that need the notion of a current thread.
Definition ThreadList.h:154
void NotifySelectedThreadChanged(lldb::tid_t tid)
ThreadList(Process &process)
lldb::ThreadSP RemoveThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
Process & m_process
The process that manages this thread list.
Definition ThreadList.h:150
std::vector< lldb::tid_t > m_expression_tid_stack
Definition ThreadList.h:155
#define LLDB_INVALID_THREAD_ID
A class that represents a running process on the host machine.
RunDirection
Execution directions.
std::shared_ptr< lldb_private::Thread > ThreadSP
uint64_t tid_t
Definition lldb-types.h:84