QueueItem.h revision 269024
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#include <vector> 14 15#include "lldb/lldb-private.h" 16#include "lldb/lldb-enumerations.h" 17 18#include "lldb/Core/Address.h" 19#include "lldb/Core/ConstString.h" 20 21 22namespace lldb_private { 23 24//------------------------------------------------------------------ 25// QueueItem: 26// This class represents a work item enqueued on a libdispatch aka 27// Grand Central Dispatch (GCD) queue. Most often, this will be a 28// function or block. 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//------------------------------------------------------------------ 33 34 35class QueueItem : 36 public std::enable_shared_from_this<QueueItem> 37{ 38public: 39 40 QueueItem (lldb::QueueSP queue_sp); 41 42 ~QueueItem (); 43 44 //------------------------------------------------------------------ 45 /// Get the kind of work item this is 46 /// 47 /// @return 48 /// The type of work item that this QueueItem object 49 /// represents. eQueueItemKindUnknown may be returned. 50 //------------------------------------------------------------------ 51 lldb::QueueItemKind 52 GetKind () const; 53 54 //------------------------------------------------------------------ 55 /// Set the type of work item this is 56 /// 57 /// @param [in] item_kind 58 /// Set the kind of this work item object. 59 //------------------------------------------------------------------ 60 void 61 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 & 76 GetAddress (); 77 78 //------------------------------------------------------------------ 79 /// Set the work item address for this object 80 /// 81 /// @param [in] addr 82 /// The address that will be invoked when this work item 83 /// is executed. 84 //------------------------------------------------------------------ 85 void 86 SetAddress (lldb_private::Address addr); 87 88 //------------------------------------------------------------------ 89 /// Check if this QueueItem object is valid 90 /// 91 /// If the weak pointer to the parent Queue cannot be revivified, 92 /// it is invalid. 93 /// 94 /// @return 95 /// True if this object is valid. 96 //------------------------------------------------------------------ 97 bool 98 IsValid () 99 { 100 return m_queue_wp.lock() != NULL; 101 } 102 103 //------------------------------------------------------------------ 104 /// Get an extended backtrace thread for this queue item, if available 105 /// 106 /// If the backtrace/thread information was collected when this item 107 /// was enqueued, this call will provide it. 108 /// 109 /// @param [in] type 110 /// The type of extended backtrace being requested, e.g. "libdispatch" 111 /// or "pthread". 112 /// 113 /// @return 114 /// A thread shared pointer which will have a reference to an extended 115 /// thread if one was available. 116 //------------------------------------------------------------------ 117 lldb::ThreadSP 118 GetExtendedBacktraceThread (ConstString type); 119 120 void 121 SetItemThatEnqueuedThis (lldb::addr_t address_of_item) 122 { 123 m_item_that_enqueued_this_ref = address_of_item; 124 } 125 126 lldb::addr_t 127 GetItemThatEnqueuedThis () 128 { 129 return m_item_that_enqueued_this_ref; 130 } 131 132 void 133 SetEnqueueingThreadID (lldb::tid_t tid) 134 { 135 m_enqueueing_thread_id = tid; 136 } 137 138 lldb::tid_t 139 GetEnqueueingThreadID () 140 { 141 return m_enqueueing_thread_id; 142 } 143 144 void 145 SetEnqueueingQueueID (lldb::queue_id_t qid) 146 { 147 m_enqueueing_queue_id = qid; 148 } 149 150 lldb::queue_id_t 151 GetEnqueueingQueueID () 152 { 153 return m_enqueueing_queue_id; 154 } 155 156 void 157 SetTargetQueueID (lldb::queue_id_t qid) 158 { 159 m_target_queue_id = qid; 160 } 161 162 void 163 SetStopID (uint32_t stop_id) 164 { 165 m_stop_id = stop_id; 166 } 167 168 uint32_t 169 GetStopID () 170 { 171 return m_stop_id; 172 } 173 174 void 175 SetEnqueueingBacktrace (std::vector<lldb::addr_t> backtrace) 176 { 177 m_backtrace = backtrace; 178 } 179 180 std::vector<lldb::addr_t> & 181 GetEnqueueingBacktrace () 182 { 183 return m_backtrace; 184 } 185 186 void 187 SetThreadLabel (std::string thread_name) 188 { 189 m_thread_label = thread_name; 190 } 191 192 std::string 193 GetThreadLabel () 194 { 195 return m_thread_label; 196 } 197 198 void 199 SetQueueLabel (std::string queue_name) 200 { 201 m_queue_label = queue_name; 202 } 203 204 std::string 205 GetQueueLabel () 206 { 207 return m_queue_label; 208 } 209 210 void 211 SetTargetQueueLabel (std::string queue_name) 212 { 213 m_target_queue_label = queue_name; 214 } 215 216protected: 217 lldb::QueueWP m_queue_wp; 218 lldb::QueueItemKind m_kind; 219 lldb_private::Address m_address; 220 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; 231 232 233private: 234 //------------------------------------------------------------------ 235 // For QueueItem only 236 //------------------------------------------------------------------ 237 238 DISALLOW_COPY_AND_ASSIGN (QueueItem); 239 240}; 241 242} // namespace lldb_private 243 244#endif // liblldb_QueueItem_h_ 245