aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Target/QueueItem.h
blob: 76270da3bee6f367ed32351f6ebb8dedb847a386 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//===-- QueueItem.h ---------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_QueueItem_h_
#define liblldb_QueueItem_h_

#include <vector>

#include "lldb/lldb-private.h"
#include "lldb/lldb-enumerations.h"

#include "lldb/Core/Address.h"
#include "lldb/Core/ConstString.h"


namespace lldb_private {

//------------------------------------------------------------------
// QueueItem:
// This class represents a work item enqueued on a libdispatch aka
// Grand Central Dispatch (GCD) queue.  Most often, this will be a
// function or block.
// "enqueued" here means that the work item has been added to a queue
// but it has not yet started executing.  When it is "dequeued", 
// execution of the item begins.
//------------------------------------------------------------------


class QueueItem :
    public std::enable_shared_from_this<QueueItem>
{
public:

    QueueItem (lldb::QueueSP queue_sp);

    ~QueueItem ();

    //------------------------------------------------------------------
    /// Get the kind of work item this is
    ///
    /// @return
    ///     The type of work item that this QueueItem object
    ///     represents.  eQueueItemKindUnknown may be returned.
    //------------------------------------------------------------------
    lldb::QueueItemKind
    GetKind () const;

    //------------------------------------------------------------------
    /// Set the type of work item this is
    ///
    /// @param [in] item_kind
    ///     Set the kind of this work item object.
    //------------------------------------------------------------------
    void
    SetKind (lldb::QueueItemKind item_kind);

    //------------------------------------------------------------------
    /// Get the code address that will be executed when this work item
    /// is executed.
    ///
    /// @return
    ///     The address that will be invoked when this work item is
    ///     executed.  Not all types of QueueItems will have an
    ///     address associated with them; check that the returned 
    ///     Address is valid, or check that the WorkItemKind is a
    ///     kind that involves an address, such as eQueueItemKindFunction
    ///     or eQueueItemKindBlock.
    //------------------------------------------------------------------
    lldb_private::Address &
    GetAddress ();

    //------------------------------------------------------------------
    /// Set the work item address for this object
    ///
    /// @param [in] addr
    ///     The address that will be invoked when this work item
    ///     is executed.
    //------------------------------------------------------------------
    void
    SetAddress (lldb_private::Address addr);

    //------------------------------------------------------------------
    /// Check if this QueueItem object is valid
    ///
    /// If the weak pointer to the parent Queue cannot be revivified,
    /// it is invalid.
    ///
    /// @return
    ///     True if this object is valid.
    //------------------------------------------------------------------
    bool
    IsValid ()
    {
        return m_queue_wp.lock() != NULL;
    }

    //------------------------------------------------------------------
    /// Get an extended backtrace thread for this queue item, if available
    ///
    /// If the backtrace/thread information was collected when this item
    /// was enqueued, this call will provide it.
    ///
    /// @param [in] type
    ///     The type of extended backtrace being requested, e.g. "libdispatch"
    ///     or "pthread".
    ///
    /// @return 
    ///     A thread shared pointer which will have a reference to an extended
    ///     thread if one was available.
    //------------------------------------------------------------------
    lldb::ThreadSP
    GetExtendedBacktraceThread (ConstString type);

    void
    SetItemThatEnqueuedThis (lldb::addr_t address_of_item)
    {
        m_item_that_enqueued_this_ref = address_of_item;
    }

    lldb::addr_t
    GetItemThatEnqueuedThis ()
    {
        return m_item_that_enqueued_this_ref;
    }

    void
    SetEnqueueingThreadID (lldb::tid_t tid)
    {
        m_enqueueing_thread_id = tid;
    }

    lldb::tid_t
    GetEnqueueingThreadID ()
    {
        return m_enqueueing_thread_id;
    }

    void
    SetEnqueueingQueueID (lldb::queue_id_t qid)
    {
        m_enqueueing_queue_id = qid;
    }

    lldb::queue_id_t
    GetEnqueueingQueueID ()
    {
        return m_enqueueing_queue_id;
    }

    void
    SetTargetQueueID (lldb::queue_id_t qid)
    {
        m_target_queue_id = qid;
    }

    void
    SetStopID (uint32_t stop_id)
    {
        m_stop_id = stop_id;
    }

    uint32_t
    GetStopID ()
    {
        return m_stop_id;
    }

    void
    SetEnqueueingBacktrace (std::vector<lldb::addr_t> backtrace)
    {
        m_backtrace = backtrace;
    }

    std::vector<lldb::addr_t> &
    GetEnqueueingBacktrace ()
    {
        return m_backtrace;
    }

    void
    SetThreadLabel (std::string thread_name)
    {
        m_thread_label = thread_name;
    }

    std::string
    GetThreadLabel ()
    {
        return m_thread_label;
    }

    void
    SetQueueLabel (std::string queue_name)
    {
        m_queue_label = queue_name;
    }

    std::string
    GetQueueLabel ()
    {
        return m_queue_label;
    }

    void
    SetTargetQueueLabel (std::string queue_name)
    {
        m_target_queue_label = queue_name;
    }

protected:
    lldb::QueueWP           m_queue_wp;
    lldb::QueueItemKind     m_kind;
    lldb_private::Address   m_address;

    lldb::addr_t            m_item_that_enqueued_this_ref;  // a handle that we can pass into libBacktraceRecording
                                                            // to get the QueueItem that enqueued this item
    lldb::tid_t             m_enqueueing_thread_id;    // thread that enqueued this item
    lldb::queue_id_t        m_enqueueing_queue_id;     // Queue that enqueued this item, if it was a queue
    lldb::queue_id_t        m_target_queue_id;
    uint32_t                m_stop_id;                 // indicates when this backtrace was recorded in time
    std::vector<lldb::addr_t>    m_backtrace;
    std::string             m_thread_label;
    std::string             m_queue_label;
    std::string             m_target_queue_label;


private:
    //------------------------------------------------------------------
    // For QueueItem only
    //------------------------------------------------------------------

    DISALLOW_COPY_AND_ASSIGN (QueueItem);

};

} // namespace lldb_private

#endif  // liblldb_QueueItem_h_