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_
17 #include "lldb/lldb-enumerations.h"
18 #include "lldb/lldb-forward.h"
19 #include "lldb/lldb-private.h"
21 #include "lldb/Core/Address.h"
22 #include "lldb/Utility/ConstString.h"
24 namespace lldb_private {
26 //------------------------------------------------------------------
28 // This class represents a work item enqueued on a libdispatch aka Grand
29 // Central Dispatch (GCD) queue. Most often, this will be a function or block.
30 // "enqueued" here means that the work item has been added to a queue but it
31 // has not yet started executing. When it is "dequeued", execution of the item
33 //------------------------------------------------------------------
35 class QueueItem : public std::enable_shared_from_this<QueueItem> {
37 QueueItem(lldb::QueueSP queue_sp, lldb::ProcessSP process_sp,
38 lldb::addr_t item_ref, lldb_private::Address address);
42 //------------------------------------------------------------------
43 /// Get the kind of work item this is
46 /// The type of work item that this QueueItem object
47 /// represents. eQueueItemKindUnknown may be returned.
48 //------------------------------------------------------------------
49 lldb::QueueItemKind GetKind();
51 //------------------------------------------------------------------
52 /// Set the type of work item this is
54 /// @param [in] item_kind
55 /// Set the kind of this work item object.
56 //------------------------------------------------------------------
57 void SetKind(lldb::QueueItemKind item_kind);
59 //------------------------------------------------------------------
60 /// Get the code address that will be executed when this work item
64 /// The address that will be invoked when this work item is
65 /// executed. Not all types of QueueItems will have an
66 /// address associated with them; check that the returned
67 /// Address is valid, or check that the WorkItemKind is a
68 /// kind that involves an address, such as eQueueItemKindFunction
69 /// or eQueueItemKindBlock.
70 //------------------------------------------------------------------
71 lldb_private::Address &GetAddress();
73 //------------------------------------------------------------------
74 /// Set the work item address for this object
77 /// The address that will be invoked when this work item
79 //------------------------------------------------------------------
80 void SetAddress(lldb_private::Address addr);
82 //------------------------------------------------------------------
83 /// Check if this QueueItem object is valid
85 /// If the weak pointer to the parent Queue cannot be revivified,
89 /// True if this object is valid.
90 //------------------------------------------------------------------
91 bool IsValid() { return m_queue_wp.lock() != nullptr; }
93 //------------------------------------------------------------------
94 /// Get an extended backtrace thread for this queue item, if available
96 /// If the backtrace/thread information was collected when this item
97 /// was enqueued, this call will provide it.
100 /// The type of extended backtrace being requested, e.g. "libdispatch"
104 /// A thread shared pointer which will have a reference to an extended
105 /// thread if one was available.
106 //------------------------------------------------------------------
107 lldb::ThreadSP GetExtendedBacktraceThread(ConstString type);
109 void SetItemThatEnqueuedThis(lldb::addr_t address_of_item) {
110 m_item_that_enqueued_this_ref = address_of_item;
113 lldb::addr_t GetItemThatEnqueuedThis();
115 void SetEnqueueingThreadID(lldb::tid_t tid) { m_enqueueing_thread_id = tid; }
117 lldb::tid_t GetEnqueueingThreadID();
119 void SetEnqueueingQueueID(lldb::queue_id_t qid) {
120 m_enqueueing_queue_id = qid;
123 lldb::queue_id_t GetEnqueueingQueueID();
125 void SetTargetQueueID(lldb::queue_id_t qid) { m_target_queue_id = qid; }
127 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
129 uint32_t GetStopID();
131 void SetEnqueueingBacktrace(std::vector<lldb::addr_t> backtrace) {
132 m_backtrace = backtrace;
135 std::vector<lldb::addr_t> &GetEnqueueingBacktrace();
137 void SetThreadLabel(std::string thread_name) { m_thread_label = thread_name; }
139 std::string GetThreadLabel();
141 void SetQueueLabel(std::string queue_name) { m_queue_label = queue_name; }
143 std::string GetQueueLabel();
145 void SetTargetQueueLabel(std::string queue_name) {
146 m_target_queue_label = queue_name;
149 lldb::ProcessSP GetProcessSP();
152 void FetchEntireItem();
154 lldb::QueueWP m_queue_wp;
155 lldb::ProcessWP m_process_wp;
157 lldb::addr_t m_item_ref; // the token we can be used to fetch more information
158 // about this queue item
159 lldb_private::Address m_address;
160 bool m_have_fetched_entire_item;
162 lldb::QueueItemKind m_kind;
163 lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into
164 // libBacktraceRecording
165 // to get the QueueItem that enqueued this item
166 lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
168 m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
169 lldb::queue_id_t m_target_queue_id;
170 uint32_t m_stop_id; // indicates when this backtrace was recorded in time
171 std::vector<lldb::addr_t> m_backtrace;
172 std::string m_thread_label;
173 std::string m_queue_label;
174 std::string m_target_queue_label;
177 DISALLOW_COPY_AND_ASSIGN(QueueItem);
180 } // namespace lldb_private
182 #endif // liblldb_QueueItem_h_