]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/QueueItem.h
Import to 0.6.1
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / QueueItem.h
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 // C Includes
14 // C++ Includes
15 #include <memory>
16 #include <string>
17 #include <vector>
18
19 // Other libraries and framework includes
20 // Project includes
21 #include "lldb/lldb-private.h"
22 #include "lldb/lldb-enumerations.h"
23 #include "lldb/lldb-forward.h"
24
25 #include "lldb/Core/Address.h"
26 #include "lldb/Core/ConstString.h"
27
28 namespace lldb_private {
29
30 //------------------------------------------------------------------
31 // QueueItem:
32 // This class represents a work item enqueued on a libdispatch aka
33 // Grand Central Dispatch (GCD) queue.  Most often, this will be a
34 // function or block.
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 //------------------------------------------------------------------
39
40 class QueueItem :
41     public std::enable_shared_from_this<QueueItem>
42 {
43 public:
44     QueueItem (lldb::QueueSP queue_sp, lldb::ProcessSP process_sp, lldb::addr_t item_ref, lldb_private::Address address);
45
46     ~QueueItem ();
47
48     //------------------------------------------------------------------
49     /// Get the kind of work item this is
50     ///
51     /// @return
52     ///     The type of work item that this QueueItem object
53     ///     represents.  eQueueItemKindUnknown may be returned.
54     //------------------------------------------------------------------
55     lldb::QueueItemKind
56     GetKind ();
57
58     //------------------------------------------------------------------
59     /// Set the type of work item this is
60     ///
61     /// @param [in] item_kind
62     ///     Set the kind of this work item object.
63     //------------------------------------------------------------------
64     void
65     SetKind (lldb::QueueItemKind item_kind);
66
67     //------------------------------------------------------------------
68     /// Get the code address that will be executed when this work item
69     /// is executed.
70     ///
71     /// @return
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 &
80     GetAddress ();
81
82     //------------------------------------------------------------------
83     /// Set the work item address for this object
84     ///
85     /// @param [in] addr
86     ///     The address that will be invoked when this work item
87     ///     is executed.
88     //------------------------------------------------------------------
89     void
90     SetAddress (lldb_private::Address addr);
91
92     //------------------------------------------------------------------
93     /// Check if this QueueItem object is valid
94     ///
95     /// If the weak pointer to the parent Queue cannot be revivified,
96     /// it is invalid.
97     ///
98     /// @return
99     ///     True if this object is valid.
100     //------------------------------------------------------------------
101     bool
102     IsValid ()
103     {
104         return m_queue_wp.lock() != nullptr;
105     }
106
107     //------------------------------------------------------------------
108     /// Get an extended backtrace thread for this queue item, if available
109     ///
110     /// If the backtrace/thread information was collected when this item
111     /// was enqueued, this call will provide it.
112     ///
113     /// @param [in] type
114     ///     The type of extended backtrace being requested, e.g. "libdispatch"
115     ///     or "pthread".
116     ///
117     /// @return 
118     ///     A thread shared pointer which will have a reference to an extended
119     ///     thread if one was available.
120     //------------------------------------------------------------------
121     lldb::ThreadSP
122     GetExtendedBacktraceThread (ConstString type);
123
124     void
125     SetItemThatEnqueuedThis (lldb::addr_t address_of_item)
126     {
127         m_item_that_enqueued_this_ref = address_of_item;
128     }
129
130     lldb::addr_t
131     GetItemThatEnqueuedThis ();
132
133     void
134     SetEnqueueingThreadID (lldb::tid_t tid)
135     {
136         m_enqueueing_thread_id = tid;
137     }
138
139     lldb::tid_t
140     GetEnqueueingThreadID ();
141
142     void
143     SetEnqueueingQueueID (lldb::queue_id_t qid)
144     {
145         m_enqueueing_queue_id = qid;
146     }
147
148     lldb::queue_id_t
149     GetEnqueueingQueueID ();
150
151     void
152     SetTargetQueueID (lldb::queue_id_t qid)
153     {
154         m_target_queue_id = qid;
155     }
156
157     void
158     SetStopID (uint32_t stop_id)
159     {
160         m_stop_id = stop_id;
161     }
162
163     uint32_t
164     GetStopID ();
165
166     void
167     SetEnqueueingBacktrace (std::vector<lldb::addr_t> backtrace)
168     {
169         m_backtrace = backtrace;
170     }
171
172     std::vector<lldb::addr_t> &
173     GetEnqueueingBacktrace ();
174
175     void
176     SetThreadLabel (std::string thread_name)
177     {
178         m_thread_label = thread_name;
179     }
180
181     std::string
182     GetThreadLabel ();
183
184     void
185     SetQueueLabel (std::string queue_name)
186     {
187         m_queue_label = queue_name;
188     }
189
190     std::string
191     GetQueueLabel ();
192
193     void
194     SetTargetQueueLabel (std::string queue_name)
195     {
196         m_target_queue_label = queue_name;
197     }
198
199     lldb::ProcessSP
200     GetProcessSP ();
201
202 protected:
203     void
204     FetchEntireItem ();
205
206     lldb::QueueWP           m_queue_wp;
207     lldb::ProcessWP         m_process_wp;
208
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;
212
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;
224
225 private:
226     DISALLOW_COPY_AND_ASSIGN (QueueItem);
227 };
228
229 } // namespace lldb_private
230
231 #endif // liblldb_QueueItem_h_