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-enumerations.h"
22 #include "lldb/lldb-forward.h"
23 #include "lldb/lldb-private.h"
25 #include "lldb/Core/Address.h"
26 #include "lldb/Utility/ConstString.h"
28 namespace lldb_private {
30 //------------------------------------------------------------------
32 // This class represents a work item enqueued on a libdispatch aka Grand
33 // Central Dispatch (GCD) queue. Most often, this will be a function or block.
34 // "enqueued" here means that the work item has been added to a queue but it
35 // has not yet started executing. When it is "dequeued", execution of the item
37 //------------------------------------------------------------------
39 class QueueItem : public std::enable_shared_from_this<QueueItem> {
41 QueueItem(lldb::QueueSP queue_sp, lldb::ProcessSP process_sp,
42 lldb::addr_t item_ref, lldb_private::Address address);
46 //------------------------------------------------------------------
47 /// Get the kind of work item this is
50 /// The type of work item that this QueueItem object
51 /// represents. eQueueItemKindUnknown may be returned.
52 //------------------------------------------------------------------
53 lldb::QueueItemKind GetKind();
55 //------------------------------------------------------------------
56 /// Set the type of work item this is
58 /// @param [in] item_kind
59 /// Set the kind of this work item object.
60 //------------------------------------------------------------------
61 void 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 &GetAddress();
77 //------------------------------------------------------------------
78 /// Set the work item address for this object
81 /// The address that will be invoked when this work item
83 //------------------------------------------------------------------
84 void SetAddress(lldb_private::Address addr);
86 //------------------------------------------------------------------
87 /// Check if this QueueItem object is valid
89 /// If the weak pointer to the parent Queue cannot be revivified,
93 /// True if this object is valid.
94 //------------------------------------------------------------------
95 bool IsValid() { return m_queue_wp.lock() != nullptr; }
97 //------------------------------------------------------------------
98 /// Get an extended backtrace thread for this queue item, if available
100 /// If the backtrace/thread information was collected when this item
101 /// was enqueued, this call will provide it.
104 /// The type of extended backtrace being requested, e.g. "libdispatch"
108 /// A thread shared pointer which will have a reference to an extended
109 /// thread if one was available.
110 //------------------------------------------------------------------
111 lldb::ThreadSP GetExtendedBacktraceThread(ConstString type);
113 void SetItemThatEnqueuedThis(lldb::addr_t address_of_item) {
114 m_item_that_enqueued_this_ref = address_of_item;
117 lldb::addr_t GetItemThatEnqueuedThis();
119 void SetEnqueueingThreadID(lldb::tid_t tid) { m_enqueueing_thread_id = tid; }
121 lldb::tid_t GetEnqueueingThreadID();
123 void SetEnqueueingQueueID(lldb::queue_id_t qid) {
124 m_enqueueing_queue_id = qid;
127 lldb::queue_id_t GetEnqueueingQueueID();
129 void SetTargetQueueID(lldb::queue_id_t qid) { m_target_queue_id = qid; }
131 void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; }
133 uint32_t GetStopID();
135 void SetEnqueueingBacktrace(std::vector<lldb::addr_t> backtrace) {
136 m_backtrace = backtrace;
139 std::vector<lldb::addr_t> &GetEnqueueingBacktrace();
141 void SetThreadLabel(std::string thread_name) { m_thread_label = thread_name; }
143 std::string GetThreadLabel();
145 void SetQueueLabel(std::string queue_name) { m_queue_label = queue_name; }
147 std::string GetQueueLabel();
149 void SetTargetQueueLabel(std::string queue_name) {
150 m_target_queue_label = queue_name;
153 lldb::ProcessSP GetProcessSP();
156 void FetchEntireItem();
158 lldb::QueueWP m_queue_wp;
159 lldb::ProcessWP m_process_wp;
161 lldb::addr_t m_item_ref; // the token we can be used to fetch more information
162 // about this queue item
163 lldb_private::Address m_address;
164 bool m_have_fetched_entire_item;
166 lldb::QueueItemKind m_kind;
167 lldb::addr_t m_item_that_enqueued_this_ref; // a handle that we can pass into
168 // libBacktraceRecording
169 // to get the QueueItem that enqueued this item
170 lldb::tid_t m_enqueueing_thread_id; // thread that enqueued this item
172 m_enqueueing_queue_id; // Queue that enqueued this item, if it was a queue
173 lldb::queue_id_t m_target_queue_id;
174 uint32_t m_stop_id; // indicates when this backtrace was recorded in time
175 std::vector<lldb::addr_t> m_backtrace;
176 std::string m_thread_label;
177 std::string m_queue_label;
178 std::string m_target_queue_label;
181 DISALLOW_COPY_AND_ASSIGN(QueueItem);
184 } // namespace lldb_private
186 #endif // liblldb_QueueItem_h_