1 //===-- QueueItem.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_QueueItem_h_
11 #define liblldb_QueueItem_h_
19 // Other libraries and framework includes
21 #include "lldb/lldb-enumerations.h"
22 #include "lldb/lldb-forward.h"
23 #include "lldb/lldb-private.h"
25 #include "lldb/Core/Address.h"
26 #include "lldb/Utility/ConstString.h"
28 namespace lldb_private {
30 //------------------------------------------------------------------
32 // This class represents a work item enqueued on a libdispatch aka
33 // Grand Central Dispatch (GCD) queue. Most often, this will be a
35 // "enqueued" here means that the work item has been added to a queue
36 // but it has not yet started executing. When it is "dequeued",
37 // execution of the item begins.
38 //------------------------------------------------------------------
40 class QueueItem : public std::enable_shared_from_this<QueueItem> {
42 QueueItem(lldb::QueueSP queue_sp, lldb::ProcessSP process_sp,
43 lldb::addr_t item_ref, lldb_private::Address address);
47 //------------------------------------------------------------------
48 /// Get the kind of work item this is
51 /// The type of work item that this QueueItem object
52 /// represents. eQueueItemKindUnknown may be returned.
53 //------------------------------------------------------------------
54 lldb::QueueItemKind GetKind();
56 //------------------------------------------------------------------
57 /// Set the type of work item this is
59 /// @param [in] item_kind
60 /// Set the kind of this work item object.
61 //------------------------------------------------------------------
62 void SetKind(lldb::QueueItemKind item_kind);
64 //------------------------------------------------------------------
65 /// Get the code address that will be executed when this work item
69 /// The address that will be invoked when this work item is
70 /// executed. Not all types of QueueItems will have an
71 /// address associated with them; check that the returned
72 /// Address is valid, or check that the WorkItemKind is a
73 /// kind that involves an address, such as eQueueItemKindFunction
74 /// or eQueueItemKindBlock.
75 //------------------------------------------------------------------
76 lldb_private::Address &GetAddress();
78 //------------------------------------------------------------------
79 /// Set the work item address for this object
82 /// The address that will be invoked when this work item
84 //------------------------------------------------------------------
85 void SetAddress(lldb_private::Address addr);
87 //------------------------------------------------------------------
88 /// Check if this QueueItem object is valid
90 /// If the weak pointer to the parent Queue cannot be revivified,
94 /// True if this object is valid.
95 //------------------------------------------------------------------
96 bool IsValid() { return m_queue_wp.lock() != nullptr; }
98 //------------------------------------------------------------------
99 /// Get an extended backtrace thread for this queue item, if available
101 /// If the backtrace/thread information was collected when this item
102 /// was enqueued, this call will provide it.
105 /// The type of extended backtrace being requested, e.g. "libdispatch"
109 /// A thread shared pointer which will have a reference to an extended
110 /// thread if one was available.
111 //------------------------------------------------------------------
112 lldb::ThreadSP GetExtendedBacktraceThread(ConstString type);
114 void SetItemThatEnqueuedThis(lldb::addr_t address_of_item) {
115 m_item_that_enqueued_this_ref = address_of_item;
118 lldb::addr_t GetItemThatEnqueuedThis();
120 void SetEnqueueingThreadID(lldb::tid_t tid) { m_enqueueing_thread_id = tid; }
122 lldb::tid_t GetEnqueueingThreadID();
124 void SetEnqueueingQueueID(lldb::queue_id_t qid) {
125 m_enqueueing_queue_id = qid;
128 lldb::queue_id_t GetEnqueueingQueueID();
130 void SetTargetQueueID(lldb::queue_id_t qid) { m_target_queue_id = qid; }
132 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
134 uint32_t GetStopID();
136 void SetEnqueueingBacktrace(std::vector<lldb::addr_t> backtrace) {
137 m_backtrace = backtrace;
140 std::vector<lldb::addr_t> &GetEnqueueingBacktrace();
142 void SetThreadLabel(std::string thread_name) { m_thread_label = thread_name; }
144 std::string GetThreadLabel();
146 void SetQueueLabel(std::string queue_name) { m_queue_label = queue_name; }
148 std::string GetQueueLabel();
150 void SetTargetQueueLabel(std::string queue_name) {
151 m_target_queue_label = queue_name;
154 lldb::ProcessSP GetProcessSP();
157 void FetchEntireItem();
159 lldb::QueueWP m_queue_wp;
160 lldb::ProcessWP m_process_wp;
162 lldb::addr_t m_item_ref; // the token we can be used to fetch more information
163 // about this queue item
164 lldb_private::Address m_address;
165 bool m_have_fetched_entire_item;
167 lldb::QueueItemKind m_kind;
168 lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into
169 // libBacktraceRecording
170 // to get the QueueItem that enqueued this item
171 lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
173 m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
174 lldb::queue_id_t m_target_queue_id;
175 uint32_t m_stop_id; // indicates when this backtrace was recorded in time
176 std::vector<lldb::addr_t> m_backtrace;
177 std::string m_thread_label;
178 std::string m_queue_label;
179 std::string m_target_queue_label;
182 DISALLOW_COPY_AND_ASSIGN(QueueItem);
185 } // namespace lldb_private
187 #endif // liblldb_QueueItem_h_