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-private.h"
22 #include "lldb/lldb-enumerations.h"
23 #include "lldb/lldb-forward.h"
25 #include "lldb/Core/Address.h"
26 #include "lldb/Core/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 //------------------------------------------------------------------
41 public std::enable_shared_from_this<QueueItem>
44 QueueItem (lldb::QueueSP queue_sp, lldb::ProcessSP process_sp, lldb::addr_t item_ref, lldb_private::Address address);
48 //------------------------------------------------------------------
49 /// Get the kind of work item this is
52 /// The type of work item that this QueueItem object
53 /// represents. eQueueItemKindUnknown may be returned.
54 //------------------------------------------------------------------
58 //------------------------------------------------------------------
59 /// Set the type of work item this is
61 /// @param [in] item_kind
62 /// Set the kind of this work item object.
63 //------------------------------------------------------------------
65 SetKind (lldb::QueueItemKind item_kind);
67 //------------------------------------------------------------------
68 /// Get the code address that will be executed when this work item
72 /// The address that will be invoked when this work item is
73 /// executed. Not all types of QueueItems will have an
74 /// address associated with them; check that the returned
75 /// Address is valid, or check that the WorkItemKind is a
76 /// kind that involves an address, such as eQueueItemKindFunction
77 /// or eQueueItemKindBlock.
78 //------------------------------------------------------------------
79 lldb_private::Address &
82 //------------------------------------------------------------------
83 /// Set the work item address for this object
86 /// The address that will be invoked when this work item
88 //------------------------------------------------------------------
90 SetAddress (lldb_private::Address addr);
92 //------------------------------------------------------------------
93 /// Check if this QueueItem object is valid
95 /// If the weak pointer to the parent Queue cannot be revivified,
99 /// True if this object is valid.
100 //------------------------------------------------------------------
104 return m_queue_wp.lock() != nullptr;
107 //------------------------------------------------------------------
108 /// Get an extended backtrace thread for this queue item, if available
110 /// If the backtrace/thread information was collected when this item
111 /// was enqueued, this call will provide it.
114 /// The type of extended backtrace being requested, e.g. "libdispatch"
118 /// A thread shared pointer which will have a reference to an extended
119 /// thread if one was available.
120 //------------------------------------------------------------------
122 GetExtendedBacktraceThread (ConstString type);
125 SetItemThatEnqueuedThis (lldb::addr_t address_of_item)
127 m_item_that_enqueued_this_ref = address_of_item;
131 GetItemThatEnqueuedThis ();
134 SetEnqueueingThreadID (lldb::tid_t tid)
136 m_enqueueing_thread_id = tid;
140 GetEnqueueingThreadID ();
143 SetEnqueueingQueueID (lldb::queue_id_t qid)
145 m_enqueueing_queue_id = qid;
149 GetEnqueueingQueueID ();
152 SetTargetQueueID (lldb::queue_id_t qid)
154 m_target_queue_id = qid;
158 SetStopID (uint32_t stop_id)
167 SetEnqueueingBacktrace (std::vector<lldb::addr_t> backtrace)
169 m_backtrace = backtrace;
172 std::vector<lldb::addr_t> &
173 GetEnqueueingBacktrace ();
176 SetThreadLabel (std::string thread_name)
178 m_thread_label = thread_name;
185 SetQueueLabel (std::string queue_name)
187 m_queue_label = queue_name;
194 SetTargetQueueLabel (std::string queue_name)
196 m_target_queue_label = queue_name;
206 lldb::QueueWP m_queue_wp;
207 lldb::ProcessWP m_process_wp;
209 lldb::addr_t m_item_ref; // the token we can be used to fetch more information about this queue item
210 lldb_private::Address m_address;
211 bool m_have_fetched_entire_item;
213 lldb::QueueItemKind m_kind;
214 lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into libBacktraceRecording
215 // to get the QueueItem that enqueued this item
216 lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
217 lldb::queue_id_t m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
218 lldb::queue_id_t m_target_queue_id;
219 uint32_t m_stop_id; // indicates when this backtrace was recorded in time
220 std::vector<lldb::addr_t> m_backtrace;
221 std::string m_thread_label;
222 std::string m_queue_label;
223 std::string m_target_queue_label;
226 DISALLOW_COPY_AND_ASSIGN (QueueItem);
229 } // namespace lldb_private
231 #endif // liblldb_QueueItem_h_