]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/QueueItem.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / QueueItem.h
1 //===-- QueueItem.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_QueueItem_h_
11 #define liblldb_QueueItem_h_
12
13 // C Includes
14 // C++ Includes
15 #include <memory>
16 #include <string>
17 #include <vector>
18
19 // Other libraries and framework includes
20 // Project includes
21 #include "lldb/lldb-enumerations.h"
22 #include "lldb/lldb-forward.h"
23 #include "lldb/lldb-private.h"
24
25 #include "lldb/Core/Address.h"
26 #include "lldb/Utility/ConstString.h"
27
28 namespace lldb_private {
29
30 //------------------------------------------------------------------
31 // QueueItem:
32 // This class represents a work item enqueued on a libdispatch aka Grand
33 // Central Dispatch (GCD) queue.  Most often, this will be a function or block.
34 // "enqueued" here means that the work item has been added to a queue but it
35 // has not yet started executing.  When it is "dequeued", execution of the item
36 // begins.
37 //------------------------------------------------------------------
38
39 class QueueItem : public std::enable_shared_from_this<QueueItem> {
40 public:
41   QueueItem(lldb::QueueSP queue_sp, lldb::ProcessSP process_sp,
42             lldb::addr_t item_ref, lldb_private::Address address);
43
44   ~QueueItem();
45
46   //------------------------------------------------------------------
47   /// Get the kind of work item this is
48   ///
49   /// @return
50   ///     The type of work item that this QueueItem object
51   ///     represents.  eQueueItemKindUnknown may be returned.
52   //------------------------------------------------------------------
53   lldb::QueueItemKind GetKind();
54
55   //------------------------------------------------------------------
56   /// Set the type of work item this is
57   ///
58   /// @param [in] item_kind
59   ///     Set the kind of this work item object.
60   //------------------------------------------------------------------
61   void SetKind(lldb::QueueItemKind item_kind);
62
63   //------------------------------------------------------------------
64   /// Get the code address that will be executed when this work item
65   /// is executed.
66   ///
67   /// @return
68   ///     The address that will be invoked when this work item is
69   ///     executed.  Not all types of QueueItems will have an
70   ///     address associated with them; check that the returned
71   ///     Address is valid, or check that the WorkItemKind is a
72   ///     kind that involves an address, such as eQueueItemKindFunction
73   ///     or eQueueItemKindBlock.
74   //------------------------------------------------------------------
75   lldb_private::Address &GetAddress();
76
77   //------------------------------------------------------------------
78   /// Set the work item address for this object
79   ///
80   /// @param [in] addr
81   ///     The address that will be invoked when this work item
82   ///     is executed.
83   //------------------------------------------------------------------
84   void SetAddress(lldb_private::Address addr);
85
86   //------------------------------------------------------------------
87   /// Check if this QueueItem object is valid
88   ///
89   /// If the weak pointer to the parent Queue cannot be revivified,
90   /// it is invalid.
91   ///
92   /// @return
93   ///     True if this object is valid.
94   //------------------------------------------------------------------
95   bool IsValid() { return m_queue_wp.lock() != nullptr; }
96
97   //------------------------------------------------------------------
98   /// Get an extended backtrace thread for this queue item, if available
99   ///
100   /// If the backtrace/thread information was collected when this item
101   /// was enqueued, this call will provide it.
102   ///
103   /// @param [in] type
104   ///     The type of extended backtrace being requested, e.g. "libdispatch"
105   ///     or "pthread".
106   ///
107   /// @return
108   ///     A thread shared pointer which will have a reference to an extended
109   ///     thread if one was available.
110   //------------------------------------------------------------------
111   lldb::ThreadSP GetExtendedBacktraceThread(ConstString type);
112
113   void SetItemThatEnqueuedThis(lldb::addr_t address_of_item) {
114     m_item_that_enqueued_this_ref = address_of_item;
115   }
116
117   lldb::addr_t GetItemThatEnqueuedThis();
118
119   void SetEnqueueingThreadID(lldb::tid_t tid) { m_enqueueing_thread_id = tid; }
120
121   lldb::tid_t GetEnqueueingThreadID();
122
123   void SetEnqueueingQueueID(lldb::queue_id_t qid) {
124     m_enqueueing_queue_id = qid;
125   }
126
127   lldb::queue_id_t GetEnqueueingQueueID();
128
129   void SetTargetQueueID(lldb::queue_id_t qid) { m_target_queue_id = qid; }
130
131   void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
132
133   uint32_t GetStopID();
134
135   void SetEnqueueingBacktrace(std::vector<lldb::addr_t> backtrace) {
136     m_backtrace = backtrace;
137   }
138
139   std::vector<lldb::addr_t> &GetEnqueueingBacktrace();
140
141   void SetThreadLabel(std::string thread_name) { m_thread_label = thread_name; }
142
143   std::string GetThreadLabel();
144
145   void SetQueueLabel(std::string queue_name) { m_queue_label = queue_name; }
146
147   std::string GetQueueLabel();
148
149   void SetTargetQueueLabel(std::string queue_name) {
150     m_target_queue_label = queue_name;
151   }
152
153   lldb::ProcessSP GetProcessSP();
154
155 protected:
156   void FetchEntireItem();
157
158   lldb::QueueWP m_queue_wp;
159   lldb::ProcessWP m_process_wp;
160
161   lldb::addr_t m_item_ref; // the token we can be used to fetch more information
162                            // about this queue item
163   lldb_private::Address m_address;
164   bool m_have_fetched_entire_item;
165
166   lldb::QueueItemKind m_kind;
167   lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into
168                                               // libBacktraceRecording
169   // to get the QueueItem that enqueued this item
170   lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
171   lldb::queue_id_t
172       m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
173   lldb::queue_id_t m_target_queue_id;
174   uint32_t m_stop_id; // indicates when this backtrace was recorded in time
175   std::vector<lldb::addr_t> m_backtrace;
176   std::string m_thread_label;
177   std::string m_queue_label;
178   std::string m_target_queue_label;
179
180 private:
181   DISALLOW_COPY_AND_ASSIGN(QueueItem);
182 };
183
184 } // namespace lldb_private
185
186 #endif // liblldb_QueueItem_h_