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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
| //===-- SBListener.cpp ------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBListener.h"
#include "SBReproducerPrivate.h"
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
#include "lldb/API/SBStream.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Utility/Broadcaster.h"
#include "lldb/Utility/Listener.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
SBListener::SBListener() : m_opaque_sp(), m_unused_ptr(nullptr) {
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBListener);
}
SBListener::SBListener(const char *name)
: m_opaque_sp(Listener::MakeListener(name)), m_unused_ptr(nullptr) {
LLDB_RECORD_CONSTRUCTOR(SBListener, (const char *), name);
}
SBListener::SBListener(const SBListener &rhs)
: m_opaque_sp(rhs.m_opaque_sp), m_unused_ptr(nullptr) {
LLDB_RECORD_CONSTRUCTOR(SBListener, (const lldb::SBListener &), rhs);
}
const lldb::SBListener &SBListener::operator=(const lldb::SBListener &rhs) {
LLDB_RECORD_METHOD(const lldb::SBListener &,
SBListener, operator=,(const lldb::SBListener &), rhs);
if (this != &rhs) {
m_opaque_sp = rhs.m_opaque_sp;
m_unused_ptr = nullptr;
}
return LLDB_RECORD_RESULT(*this);
}
SBListener::SBListener(const lldb::ListenerSP &listener_sp)
: m_opaque_sp(listener_sp), m_unused_ptr(nullptr) {}
SBListener::~SBListener() {}
bool SBListener::IsValid() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBListener, IsValid);
return this->operator bool();
}
SBListener::operator bool() const {
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBListener, operator bool);
return m_opaque_sp != nullptr;
}
void SBListener::AddEvent(const SBEvent &event) {
LLDB_RECORD_METHOD(void, SBListener, AddEvent, (const lldb::SBEvent &),
event);
EventSP &event_sp = event.GetSP();
if (event_sp)
m_opaque_sp->AddEvent(event_sp);
}
void SBListener::Clear() {
LLDB_RECORD_METHOD_NO_ARGS(void, SBListener, Clear);
if (m_opaque_sp)
m_opaque_sp->Clear();
}
uint32_t SBListener::StartListeningForEventClass(SBDebugger &debugger,
const char *broadcaster_class,
uint32_t event_mask) {
LLDB_RECORD_METHOD(uint32_t, SBListener, StartListeningForEventClass,
(lldb::SBDebugger &, const char *, uint32_t), debugger,
broadcaster_class, event_mask);
if (m_opaque_sp) {
Debugger *lldb_debugger = debugger.get();
if (!lldb_debugger)
return 0;
BroadcastEventSpec event_spec(ConstString(broadcaster_class), event_mask);
return m_opaque_sp->StartListeningForEventSpec(
lldb_debugger->GetBroadcasterManager(), event_spec);
} else
return 0;
}
bool SBListener::StopListeningForEventClass(SBDebugger &debugger,
const char *broadcaster_class,
uint32_t event_mask) {
LLDB_RECORD_METHOD(bool, SBListener, StopListeningForEventClass,
(lldb::SBDebugger &, const char *, uint32_t), debugger,
broadcaster_class, event_mask);
if (m_opaque_sp) {
Debugger *lldb_debugger = debugger.get();
if (!lldb_debugger)
return false;
BroadcastEventSpec event_spec(ConstString(broadcaster_class), event_mask);
return m_opaque_sp->StopListeningForEventSpec(
lldb_debugger->GetBroadcasterManager(), event_spec);
} else
return false;
}
uint32_t SBListener::StartListeningForEvents(const SBBroadcaster &broadcaster,
uint32_t event_mask) {
LLDB_RECORD_METHOD(uint32_t, SBListener, StartListeningForEvents,
(const lldb::SBBroadcaster &, uint32_t), broadcaster,
event_mask);
uint32_t acquired_event_mask = 0;
if (m_opaque_sp && broadcaster.IsValid()) {
acquired_event_mask =
m_opaque_sp->StartListeningForEvents(broadcaster.get(), event_mask);
}
return acquired_event_mask;
}
bool SBListener::StopListeningForEvents(const SBBroadcaster &broadcaster,
uint32_t event_mask) {
LLDB_RECORD_METHOD(bool, SBListener, StopListeningForEvents,
(const lldb::SBBroadcaster &, uint32_t), broadcaster,
event_mask);
if (m_opaque_sp && broadcaster.IsValid()) {
return m_opaque_sp->StopListeningForEvents(broadcaster.get(), event_mask);
}
return false;
}
bool SBListener::WaitForEvent(uint32_t timeout_secs, SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, WaitForEvent,
(uint32_t, lldb::SBEvent &), timeout_secs, event);
bool success = false;
if (m_opaque_sp) {
Timeout<std::micro> timeout(llvm::None);
if (timeout_secs != UINT32_MAX) {
assert(timeout_secs != 0); // Take this out after all calls with timeout
// set to zero have been removed....
timeout = std::chrono::seconds(timeout_secs);
}
EventSP event_sp;
if (m_opaque_sp->GetEvent(event_sp, timeout)) {
event.reset(event_sp);
success = true;
}
}
if (!success)
event.reset(nullptr);
return success;
}
bool SBListener::WaitForEventForBroadcaster(uint32_t num_seconds,
const SBBroadcaster &broadcaster,
SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, WaitForEventForBroadcaster,
(uint32_t, const lldb::SBBroadcaster &, lldb::SBEvent &),
num_seconds, broadcaster, event);
if (m_opaque_sp && broadcaster.IsValid()) {
Timeout<std::micro> timeout(llvm::None);
if (num_seconds != UINT32_MAX)
timeout = std::chrono::seconds(num_seconds);
EventSP event_sp;
if (m_opaque_sp->GetEventForBroadcaster(broadcaster.get(), event_sp,
timeout)) {
event.reset(event_sp);
return true;
}
}
event.reset(nullptr);
return false;
}
bool SBListener::WaitForEventForBroadcasterWithType(
uint32_t num_seconds, const SBBroadcaster &broadcaster,
uint32_t event_type_mask, SBEvent &event) {
LLDB_RECORD_METHOD(
bool, SBListener, WaitForEventForBroadcasterWithType,
(uint32_t, const lldb::SBBroadcaster &, uint32_t, lldb::SBEvent &),
num_seconds, broadcaster, event_type_mask, event);
if (m_opaque_sp && broadcaster.IsValid()) {
Timeout<std::micro> timeout(llvm::None);
if (num_seconds != UINT32_MAX)
timeout = std::chrono::seconds(num_seconds);
EventSP event_sp;
if (m_opaque_sp->GetEventForBroadcasterWithType(
broadcaster.get(), event_type_mask, event_sp, timeout)) {
event.reset(event_sp);
return true;
}
}
event.reset(nullptr);
return false;
}
bool SBListener::PeekAtNextEvent(SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, PeekAtNextEvent, (lldb::SBEvent &),
event);
if (m_opaque_sp) {
event.reset(m_opaque_sp->PeekAtNextEvent());
return event.IsValid();
}
event.reset(nullptr);
return false;
}
bool SBListener::PeekAtNextEventForBroadcaster(const SBBroadcaster &broadcaster,
SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, PeekAtNextEventForBroadcaster,
(const lldb::SBBroadcaster &, lldb::SBEvent &),
broadcaster, event);
if (m_opaque_sp && broadcaster.IsValid()) {
event.reset(m_opaque_sp->PeekAtNextEventForBroadcaster(broadcaster.get()));
return event.IsValid();
}
event.reset(nullptr);
return false;
}
bool SBListener::PeekAtNextEventForBroadcasterWithType(
const SBBroadcaster &broadcaster, uint32_t event_type_mask,
SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, PeekAtNextEventForBroadcasterWithType,
(const lldb::SBBroadcaster &, uint32_t, lldb::SBEvent &),
broadcaster, event_type_mask, event);
if (m_opaque_sp && broadcaster.IsValid()) {
event.reset(m_opaque_sp->PeekAtNextEventForBroadcasterWithType(
broadcaster.get(), event_type_mask));
return event.IsValid();
}
event.reset(nullptr);
return false;
}
bool SBListener::GetNextEvent(SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, GetNextEvent, (lldb::SBEvent &), event);
if (m_opaque_sp) {
EventSP event_sp;
if (m_opaque_sp->GetEvent(event_sp, std::chrono::seconds(0))) {
event.reset(event_sp);
return true;
}
}
event.reset(nullptr);
return false;
}
bool SBListener::GetNextEventForBroadcaster(const SBBroadcaster &broadcaster,
SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, GetNextEventForBroadcaster,
(const lldb::SBBroadcaster &, lldb::SBEvent &),
broadcaster, event);
if (m_opaque_sp && broadcaster.IsValid()) {
EventSP event_sp;
if (m_opaque_sp->GetEventForBroadcaster(broadcaster.get(), event_sp,
std::chrono::seconds(0))) {
event.reset(event_sp);
return true;
}
}
event.reset(nullptr);
return false;
}
bool SBListener::GetNextEventForBroadcasterWithType(
const SBBroadcaster &broadcaster, uint32_t event_type_mask,
SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, GetNextEventForBroadcasterWithType,
(const lldb::SBBroadcaster &, uint32_t, lldb::SBEvent &),
broadcaster, event_type_mask, event);
if (m_opaque_sp && broadcaster.IsValid()) {
EventSP event_sp;
if (m_opaque_sp->GetEventForBroadcasterWithType(broadcaster.get(),
event_type_mask, event_sp,
std::chrono::seconds(0))) {
event.reset(event_sp);
return true;
}
}
event.reset(nullptr);
return false;
}
bool SBListener::HandleBroadcastEvent(const SBEvent &event) {
LLDB_RECORD_METHOD(bool, SBListener, HandleBroadcastEvent,
(const lldb::SBEvent &), event);
if (m_opaque_sp)
return m_opaque_sp->HandleBroadcastEvent(event.GetSP());
return false;
}
lldb::ListenerSP SBListener::GetSP() { return m_opaque_sp; }
Listener *SBListener::operator->() const { return m_opaque_sp.get(); }
Listener *SBListener::get() const { return m_opaque_sp.get(); }
void SBListener::reset(ListenerSP listener_sp) {
m_opaque_sp = listener_sp;
m_unused_ptr = nullptr;
}
namespace lldb_private {
namespace repro {
template <>
void RegisterMethods<SBListener>(Registry &R) {
LLDB_REGISTER_CONSTRUCTOR(SBListener, ());
LLDB_REGISTER_CONSTRUCTOR(SBListener, (const char *));
LLDB_REGISTER_CONSTRUCTOR(SBListener, (const lldb::SBListener &));
LLDB_REGISTER_METHOD(const lldb::SBListener &,
SBListener, operator=,(const lldb::SBListener &));
LLDB_REGISTER_METHOD_CONST(bool, SBListener, IsValid, ());
LLDB_REGISTER_METHOD_CONST(bool, SBListener, operator bool, ());
LLDB_REGISTER_METHOD(void, SBListener, AddEvent, (const lldb::SBEvent &));
LLDB_REGISTER_METHOD(void, SBListener, Clear, ());
LLDB_REGISTER_METHOD(uint32_t, SBListener, StartListeningForEventClass,
(lldb::SBDebugger &, const char *, uint32_t));
LLDB_REGISTER_METHOD(bool, SBListener, StopListeningForEventClass,
(lldb::SBDebugger &, const char *, uint32_t));
LLDB_REGISTER_METHOD(uint32_t, SBListener, StartListeningForEvents,
(const lldb::SBBroadcaster &, uint32_t));
LLDB_REGISTER_METHOD(bool, SBListener, StopListeningForEvents,
(const lldb::SBBroadcaster &, uint32_t));
LLDB_REGISTER_METHOD(bool, SBListener, WaitForEvent,
(uint32_t, lldb::SBEvent &));
LLDB_REGISTER_METHOD(
bool, SBListener, WaitForEventForBroadcaster,
(uint32_t, const lldb::SBBroadcaster &, lldb::SBEvent &));
LLDB_REGISTER_METHOD(
bool, SBListener, WaitForEventForBroadcasterWithType,
(uint32_t, const lldb::SBBroadcaster &, uint32_t, lldb::SBEvent &));
LLDB_REGISTER_METHOD(bool, SBListener, PeekAtNextEvent, (lldb::SBEvent &));
LLDB_REGISTER_METHOD(bool, SBListener, PeekAtNextEventForBroadcaster,
(const lldb::SBBroadcaster &, lldb::SBEvent &));
LLDB_REGISTER_METHOD(
bool, SBListener, PeekAtNextEventForBroadcasterWithType,
(const lldb::SBBroadcaster &, uint32_t, lldb::SBEvent &));
LLDB_REGISTER_METHOD(bool, SBListener, GetNextEvent, (lldb::SBEvent &));
LLDB_REGISTER_METHOD(bool, SBListener, GetNextEventForBroadcaster,
(const lldb::SBBroadcaster &, lldb::SBEvent &));
LLDB_REGISTER_METHOD(
bool, SBListener, GetNextEventForBroadcasterWithType,
(const lldb::SBBroadcaster &, uint32_t, lldb::SBEvent &));
LLDB_REGISTER_METHOD(bool, SBListener, HandleBroadcastEvent,
(const lldb::SBEvent &));
}
}
}
|