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
245
246
247
248
249
250
251
252
253
254
255
256
|
//===-- SBQueue.cpp ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/lldb-python.h"
#include "lldb/API/SBQueue.h"
#include "lldb/API/SBProcess.h"
#include "lldb/API/SBThread.h"
#include "lldb/Core/Log.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Queue.h"
#include "lldb/Target/QueueItem.h"
#include "lldb/Target/Thread.h"
using namespace lldb;
using namespace lldb_private;
//----------------------------------------------------------------------
// Constructors
//----------------------------------------------------------------------
SBQueue::SBQueue () :
m_queue_wp(),
m_threads(),
m_thread_list_fetched(false),
m_items(),
m_queue_items_fetched(false)
{
}
SBQueue::SBQueue (const QueueSP& queue_sp) :
m_queue_wp(queue_sp),
m_threads(),
m_thread_list_fetched(false),
m_items(),
m_queue_items_fetched(false)
{
}
//----------------------------------------------------------------------
// Destructor
//----------------------------------------------------------------------
SBQueue::~SBQueue()
{
m_threads.clear();
m_items.clear();
}
bool
SBQueue::IsValid() const
{
QueueSP queue_sp = m_queue_wp.lock();
return queue_sp.get() != NULL;
}
void
SBQueue::Clear ()
{
m_queue_wp.reset();
m_thread_list_fetched = false;
m_threads.clear();
m_queue_items_fetched = false;
m_items.clear();
}
void
SBQueue::SetQueue (const QueueSP& queue_sp)
{
m_queue_wp = queue_sp;
m_thread_list_fetched = false;
m_threads.clear();
m_queue_items_fetched = false;
m_items.clear();
}
lldb::queue_id_t
SBQueue::GetQueueID () const
{
queue_id_t result = LLDB_INVALID_QUEUE_ID;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result = queue_sp->GetID();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetQueueID () => 0x%" PRIx64, this, result);
return result;
}
uint32_t
SBQueue::GetIndexID () const
{
uint32_t result = LLDB_INVALID_INDEX32;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result = queue_sp->GetIndexID();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetIndexID () => %d", this, result);
return result;
}
const char *
SBQueue::GetName () const
{
const char *name = NULL;
QueueSP queue_sp = m_queue_wp.lock ();
if (queue_sp.get())
{
name = queue_sp->GetName();
}
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
if (log)
log->Printf ("SBQueue(%p)::GetName () => %s", this, name ? name : "NULL");
return name;
}
void
SBQueue::FetchThreads ()
{
if (m_thread_list_fetched == false)
{
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
Process::StopLocker stop_locker;
if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
{
const std::vector<ThreadSP> thread_list(queue_sp->GetThreads());
m_thread_list_fetched = true;
const uint32_t num_threads = thread_list.size();
for (uint32_t idx = 0; idx < num_threads; ++idx)
{
ThreadSP thread_sp = thread_list[idx];
if (thread_sp && thread_sp->IsValid())
{
m_threads.push_back (thread_sp);
}
}
}
}
}
}
void
SBQueue::FetchItems ()
{
if (m_queue_items_fetched == false)
{
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
Process::StopLocker stop_locker;
if (stop_locker.TryLock (&queue_sp->GetProcess()->GetRunLock()))
{
const std::vector<QueueItemSP> queue_items(queue_sp->GetItems());
m_queue_items_fetched = true;
const uint32_t num_items = queue_items.size();
for (uint32_t idx = 0; idx < num_items; ++idx)
{
QueueItemSP item = queue_items[idx];
if (item && item->IsValid())
{
m_items.push_back (item);
}
}
}
}
}
}
uint32_t
SBQueue::GetNumThreads ()
{
uint32_t result = 0;
FetchThreads();
if (m_thread_list_fetched)
{
result = m_threads.size();
}
return result;
}
SBThread
SBQueue::GetThreadAtIndex (uint32_t idx)
{
FetchThreads();
SBThread sb_thread;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp && idx < m_threads.size())
{
ProcessSP process_sp = queue_sp->GetProcess();
if (process_sp)
{
ThreadSP thread_sp = m_threads[idx].lock();
if (thread_sp)
{
sb_thread.SetThread (thread_sp);
}
}
}
return sb_thread;
}
uint32_t
SBQueue::GetNumItems ()
{
uint32_t result = 0;
FetchItems();
if (m_queue_items_fetched)
{
result = m_items.size();
}
return result;
}
SBQueueItem
SBQueue::GetItemAtIndex (uint32_t idx)
{
SBQueueItem result;
FetchItems();
if (m_queue_items_fetched && idx < m_items.size())
{
result.SetQueueItem (m_items[idx]);
}
return result;
}
SBProcess
SBQueue::GetProcess ()
{
SBProcess result;
QueueSP queue_sp = m_queue_wp.lock();
if (queue_sp)
{
result.SetSP (queue_sp->GetProcess());
}
return result;
}
|