1262182Semaste//===-- QueueItem.h ---------------------------------------------*- C++ -*-===// 2262182Semaste// 3262182Semaste// The LLVM Compiler Infrastructure 4262182Semaste// 5262182Semaste// This file is distributed under the University of Illinois Open Source 6262182Semaste// License. See LICENSE.TXT for details. 7262182Semaste// 8262182Semaste//===----------------------------------------------------------------------===// 9262182Semaste 10262182Semaste#ifndef liblldb_QueueItem_h_ 11262182Semaste#define liblldb_QueueItem_h_ 12262182Semaste 13262182Semaste#include <vector> 14262182Semaste 15262182Semaste#include "lldb/lldb-private.h" 16262182Semaste#include "lldb/lldb-enumerations.h" 17262182Semaste 18262182Semaste#include "lldb/Core/Address.h" 19262182Semaste#include "lldb/Core/ConstString.h" 20262182Semaste 21262182Semaste 22262182Semastenamespace lldb_private { 23262182Semaste 24262182Semaste//------------------------------------------------------------------ 25262182Semaste// QueueItem: 26262182Semaste// This class represents a work item enqueued on a libdispatch aka 27262182Semaste// Grand Central Dispatch (GCD) queue. Most often, this will be a 28262182Semaste// function or block. 29262182Semaste// "enqueued" here means that the work item has been added to a queue 30262182Semaste// but it has not yet started executing. When it is "dequeued", 31262182Semaste// execution of the item begins. 32262182Semaste//------------------------------------------------------------------ 33262182Semaste 34262182Semaste 35262182Semasteclass QueueItem : 36262182Semaste public std::enable_shared_from_this<QueueItem> 37262182Semaste{ 38262182Semastepublic: 39262182Semaste 40262182Semaste QueueItem (lldb::QueueSP queue_sp); 41262182Semaste 42262182Semaste ~QueueItem (); 43262182Semaste 44262182Semaste //------------------------------------------------------------------ 45262182Semaste /// Get the kind of work item this is 46262182Semaste /// 47262182Semaste /// @return 48262182Semaste /// The type of work item that this QueueItem object 49262182Semaste /// represents. eQueueItemKindUnknown may be returned. 50262182Semaste //------------------------------------------------------------------ 51262182Semaste lldb::QueueItemKind 52262182Semaste GetKind () const; 53262182Semaste 54262182Semaste //------------------------------------------------------------------ 55262182Semaste /// Set the type of work item this is 56262182Semaste /// 57262182Semaste /// @param [in] item_kind 58262182Semaste /// Set the kind of this work item object. 59262182Semaste //------------------------------------------------------------------ 60262182Semaste void 61262182Semaste SetKind (lldb::QueueItemKind item_kind); 62262182Semaste 63262182Semaste //------------------------------------------------------------------ 64262182Semaste /// Get the code address that will be executed when this work item 65262182Semaste /// is executed. 66262182Semaste /// 67262182Semaste /// @return 68262182Semaste /// The address that will be invoked when this work item is 69262182Semaste /// executed. Not all types of QueueItems will have an 70262182Semaste /// address associated with them; check that the returned 71262182Semaste /// Address is valid, or check that the WorkItemKind is a 72262182Semaste /// kind that involves an address, such as eQueueItemKindFunction 73262182Semaste /// or eQueueItemKindBlock. 74262182Semaste //------------------------------------------------------------------ 75262182Semaste lldb_private::Address & 76262182Semaste GetAddress (); 77262182Semaste 78262182Semaste //------------------------------------------------------------------ 79262182Semaste /// Set the work item address for this object 80262182Semaste /// 81262182Semaste /// @param [in] addr 82262182Semaste /// The address that will be invoked when this work item 83262182Semaste /// is executed. 84262182Semaste //------------------------------------------------------------------ 85262182Semaste void 86262182Semaste SetAddress (lldb_private::Address addr); 87262182Semaste 88262182Semaste //------------------------------------------------------------------ 89262182Semaste /// Check if this QueueItem object is valid 90262182Semaste /// 91262182Semaste /// If the weak pointer to the parent Queue cannot be revivified, 92262182Semaste /// it is invalid. 93262182Semaste /// 94262182Semaste /// @return 95262182Semaste /// True if this object is valid. 96262182Semaste //------------------------------------------------------------------ 97262182Semaste bool 98262182Semaste IsValid () 99262182Semaste { 100262182Semaste return m_queue_wp.lock() != NULL; 101262182Semaste } 102262182Semaste 103262182Semaste //------------------------------------------------------------------ 104262182Semaste /// Get an extended backtrace thread for this queue item, if available 105262182Semaste /// 106262182Semaste /// If the backtrace/thread information was collected when this item 107262182Semaste /// was enqueued, this call will provide it. 108262182Semaste /// 109262182Semaste /// @param [in] type 110262182Semaste /// The type of extended backtrace being requested, e.g. "libdispatch" 111262182Semaste /// or "pthread". 112262182Semaste /// 113262182Semaste /// @return 114262182Semaste /// A thread shared pointer which will have a reference to an extended 115262182Semaste /// thread if one was available. 116262182Semaste //------------------------------------------------------------------ 117262182Semaste lldb::ThreadSP 118262182Semaste GetExtendedBacktraceThread (ConstString type); 119262182Semaste 120262182Semaste void 121262182Semaste SetItemThatEnqueuedThis (lldb::addr_t address_of_item) 122262182Semaste { 123262182Semaste m_item_that_enqueued_this_ref = address_of_item; 124262182Semaste } 125262182Semaste 126262182Semaste lldb::addr_t 127262182Semaste GetItemThatEnqueuedThis () 128262182Semaste { 129262182Semaste return m_item_that_enqueued_this_ref; 130262182Semaste } 131262182Semaste 132262182Semaste void 133262182Semaste SetEnqueueingThreadID (lldb::tid_t tid) 134262182Semaste { 135262182Semaste m_enqueueing_thread_id = tid; 136262182Semaste } 137262182Semaste 138262182Semaste lldb::tid_t 139262182Semaste GetEnqueueingThreadID () 140262182Semaste { 141262182Semaste return m_enqueueing_thread_id; 142262182Semaste } 143262182Semaste 144262182Semaste void 145262182Semaste SetEnqueueingQueueID (lldb::queue_id_t qid) 146262182Semaste { 147262182Semaste m_enqueueing_queue_id = qid; 148262182Semaste } 149262182Semaste 150262182Semaste lldb::queue_id_t 151262182Semaste GetEnqueueingQueueID () 152262182Semaste { 153262182Semaste return m_enqueueing_queue_id; 154262182Semaste } 155262182Semaste 156262182Semaste void 157262182Semaste SetTargetQueueID (lldb::queue_id_t qid) 158262182Semaste { 159262182Semaste m_target_queue_id = qid; 160262182Semaste } 161262182Semaste 162262182Semaste void 163262182Semaste SetStopID (uint32_t stop_id) 164262182Semaste { 165262182Semaste m_stop_id = stop_id; 166262182Semaste } 167262182Semaste 168262182Semaste uint32_t 169262182Semaste GetStopID () 170262182Semaste { 171262182Semaste return m_stop_id; 172262182Semaste } 173262182Semaste 174262182Semaste void 175262182Semaste SetEnqueueingBacktrace (std::vector<lldb::addr_t> backtrace) 176262182Semaste { 177262182Semaste m_backtrace = backtrace; 178262182Semaste } 179262182Semaste 180262182Semaste std::vector<lldb::addr_t> & 181262182Semaste GetEnqueueingBacktrace () 182262182Semaste { 183262182Semaste return m_backtrace; 184262182Semaste } 185262182Semaste 186262182Semaste void 187262182Semaste SetThreadLabel (std::string thread_name) 188262182Semaste { 189262182Semaste m_thread_label = thread_name; 190262182Semaste } 191262182Semaste 192262182Semaste std::string 193262182Semaste GetThreadLabel () 194262182Semaste { 195262182Semaste return m_thread_label; 196262182Semaste } 197262182Semaste 198262182Semaste void 199262182Semaste SetQueueLabel (std::string queue_name) 200262182Semaste { 201262182Semaste m_queue_label = queue_name; 202262182Semaste } 203262182Semaste 204262182Semaste std::string 205262182Semaste GetQueueLabel () 206262182Semaste { 207262182Semaste return m_queue_label; 208262182Semaste } 209262182Semaste 210262182Semaste void 211262182Semaste SetTargetQueueLabel (std::string queue_name) 212262182Semaste { 213262182Semaste m_target_queue_label = queue_name; 214262182Semaste } 215262182Semaste 216262182Semasteprotected: 217262182Semaste lldb::QueueWP m_queue_wp; 218262182Semaste lldb::QueueItemKind m_kind; 219262182Semaste lldb_private::Address m_address; 220262182Semaste 221262182Semaste lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into libBacktraceRecording 222262182Semaste // to get the QueueItem that enqueued this item 223262182Semaste lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item 224262182Semaste lldb::queue_id_t m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue 225262182Semaste lldb::queue_id_t m_target_queue_id; 226262182Semaste uint32_t m_stop_id; // indicates when this backtrace was recorded in time 227262182Semaste std::vector<lldb::addr_t> m_backtrace; 228262182Semaste std::string m_thread_label; 229262182Semaste std::string m_queue_label; 230262182Semaste std::string m_target_queue_label; 231262182Semaste 232262182Semaste 233262182Semasteprivate: 234262182Semaste //------------------------------------------------------------------ 235262182Semaste // For QueueItem only 236262182Semaste //------------------------------------------------------------------ 237262182Semaste 238262182Semaste DISALLOW_COPY_AND_ASSIGN (QueueItem); 239262182Semaste 240262182Semaste}; 241262182Semaste 242262182Semaste} // namespace lldb_private 243262182Semaste 244262182Semaste#endif // liblldb_QueueItem_h_ 245