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_
15 #include "lldb/lldb-private.h"
16 #include "lldb/lldb-enumerations.h"
18 #include "lldb/Core/Address.h"
19 #include "lldb/Core/ConstString.h"
22 namespace lldb_private {
24 //------------------------------------------------------------------
26 // This class represents a work item enqueued on a libdispatch aka
27 // Grand Central Dispatch (GCD) queue. Most often, this will be a
29 // "enqueued" here means that the work item has been added to a queue
30 // but it has not yet started executing. When it is "dequeued",
31 // execution of the item begins.
32 //------------------------------------------------------------------
36 public std::enable_shared_from_this<QueueItem>
40 QueueItem (lldb::QueueSP queue_sp);
44 //------------------------------------------------------------------
45 /// Get the kind of work item this is
48 /// The type of work item that this QueueItem object
49 /// represents. eQueueItemKindUnknown may be returned.
50 //------------------------------------------------------------------
54 //------------------------------------------------------------------
55 /// Set the type of work item this is
57 /// @param [in] item_kind
58 /// Set the kind of this work item object.
59 //------------------------------------------------------------------
61 SetKind (lldb::QueueItemKind item_kind);
63 //------------------------------------------------------------------
64 /// Get the code address that will be executed when this work item
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 &
78 //------------------------------------------------------------------
79 /// Set the work item address for this object
82 /// The address that will be invoked when this work item
84 //------------------------------------------------------------------
86 SetAddress (lldb_private::Address addr);
88 //------------------------------------------------------------------
89 /// Check if this QueueItem object is valid
91 /// If the weak pointer to the parent Queue cannot be revivified,
95 /// True if this object is valid.
96 //------------------------------------------------------------------
100 return m_queue_wp.lock() != NULL;
103 //------------------------------------------------------------------
104 /// Get an extended backtrace thread for this queue item, if available
106 /// If the backtrace/thread information was collected when this item
107 /// was enqueued, this call will provide it.
110 /// The type of extended backtrace being requested, e.g. "libdispatch"
114 /// A thread shared pointer which will have a reference to an extended
115 /// thread if one was available.
116 //------------------------------------------------------------------
118 GetExtendedBacktraceThread (ConstString type);
121 SetItemThatEnqueuedThis (lldb::addr_t address_of_item)
123 m_item_that_enqueued_this_ref = address_of_item;
127 GetItemThatEnqueuedThis ()
129 return m_item_that_enqueued_this_ref;
133 SetEnqueueingThreadID (lldb::tid_t tid)
135 m_enqueueing_thread_id = tid;
139 GetEnqueueingThreadID ()
141 return m_enqueueing_thread_id;
145 SetEnqueueingQueueID (lldb::queue_id_t qid)
147 m_enqueueing_queue_id = qid;
151 GetEnqueueingQueueID ()
153 return m_enqueueing_queue_id;
157 SetTargetQueueID (lldb::queue_id_t qid)
159 m_target_queue_id = qid;
163 SetStopID (uint32_t stop_id)
175 SetEnqueueingBacktrace (std::vector<lldb::addr_t> backtrace)
177 m_backtrace = backtrace;
180 std::vector<lldb::addr_t> &
181 GetEnqueueingBacktrace ()
187 SetThreadLabel (std::string thread_name)
189 m_thread_label = thread_name;
195 return m_thread_label;
199 SetQueueLabel (std::string queue_name)
201 m_queue_label = queue_name;
207 return m_queue_label;
211 SetTargetQueueLabel (std::string queue_name)
213 m_target_queue_label = queue_name;
217 lldb::QueueWP m_queue_wp;
218 lldb::QueueItemKind m_kind;
219 lldb_private::Address m_address;
221 lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into libBacktraceRecording
222 // to get the QueueItem that enqueued this item
223 lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
224 lldb::queue_id_t m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
225 lldb::queue_id_t m_target_queue_id;
226 uint32_t m_stop_id; // indicates when this backtrace was recorded in time
227 std::vector<lldb::addr_t> m_backtrace;
228 std::string m_thread_label;
229 std::string m_queue_label;
230 std::string m_target_queue_label;
234 //------------------------------------------------------------------
235 // For QueueItem only
236 //------------------------------------------------------------------
238 DISALLOW_COPY_AND_ASSIGN (QueueItem);
242 } // namespace lldb_private
244 #endif // liblldb_QueueItem_h_