Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/API/SBEvent.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- SBEvent.cpp -------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/API/SBEvent.h"
10
#include "lldb/API/SBBroadcaster.h"
11
#include "lldb/API/SBStream.h"
12
#include "lldb/Utility/Instrumentation.h"
13
14
#include "lldb/Breakpoint/Breakpoint.h"
15
#include "lldb/Interpreter/CommandInterpreter.h"
16
#include "lldb/Target/Process.h"
17
#include "lldb/Utility/ConstString.h"
18
#include "lldb/Utility/Event.h"
19
#include "lldb/Utility/Stream.h"
20
21
using namespace lldb;
22
using namespace lldb_private;
23
24
187
SBEvent::SBEvent() { LLDB_INSTRUMENT_VA(this); }
25
26
SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
27
1
    : m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
28
1
      m_opaque_ptr(m_event_sp.get()) {
29
1
  LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
30
1
}
31
32
SBEvent::SBEvent(EventSP &event_sp)
33
9
    : m_event_sp(event_sp), m_opaque_ptr(event_sp.get()) {
34
9
  LLDB_INSTRUMENT_VA(this, event_sp);
35
9
}
36
37
16
SBEvent::SBEvent(Event *event_ptr) : m_opaque_ptr(event_ptr) {
38
16
  LLDB_INSTRUMENT_VA(this, event_ptr);
39
16
}
40
41
SBEvent::SBEvent(const SBEvent &rhs)
42
0
    : m_event_sp(rhs.m_event_sp), m_opaque_ptr(rhs.m_opaque_ptr) {
43
0
  LLDB_INSTRUMENT_VA(this, rhs);
44
0
}
45
46
16
const SBEvent &SBEvent::operator=(const SBEvent &rhs) {
47
16
  LLDB_INSTRUMENT_VA(this, rhs);
48
49
16
  if (this != &rhs) {
50
16
    m_event_sp = rhs.m_event_sp;
51
16
    m_opaque_ptr = rhs.m_opaque_ptr;
52
16
  }
53
16
  return *this;
54
16
}
55
56
213
SBEvent::~SBEvent() = default;
57
58
5
const char *SBEvent::GetDataFlavor() {
59
5
  LLDB_INSTRUMENT_VA(this);
60
61
5
  Event *lldb_event = get();
62
5
  if (lldb_event) {
63
4
    EventData *event_data = lldb_event->GetData();
64
4
    if (event_data)
65
4
      return ConstString(lldb_event->GetData()->GetFlavor()).GetCString();
66
4
  }
67
1
  return nullptr;
68
5
}
69
70
41
uint32_t SBEvent::GetType() const {
71
41
  LLDB_INSTRUMENT_VA(this);
72
73
41
  const Event *lldb_event = get();
74
41
  uint32_t event_type = 0;
75
41
  if (lldb_event)
76
40
    event_type = lldb_event->GetType();
77
78
79
41
  return event_type;
80
41
}
81
82
1
SBBroadcaster SBEvent::GetBroadcaster() const {
83
1
  LLDB_INSTRUMENT_VA(this);
84
85
1
  SBBroadcaster broadcaster;
86
1
  const Event *lldb_event = get();
87
1
  if (lldb_event)
88
0
    broadcaster.reset(lldb_event->GetBroadcaster(), false);
89
1
  return broadcaster;
90
1
}
91
92
0
const char *SBEvent::GetBroadcasterClass() const {
93
0
  LLDB_INSTRUMENT_VA(this);
94
95
0
  const Event *lldb_event = get();
96
0
  if (lldb_event)
97
0
    return lldb_event->GetBroadcaster()->GetBroadcasterClass().AsCString();
98
0
  else
99
0
    return "unknown class";
100
0
}
101
102
0
bool SBEvent::BroadcasterMatchesPtr(const SBBroadcaster *broadcaster) {
103
0
  LLDB_INSTRUMENT_VA(this, broadcaster);
104
105
0
  if (broadcaster)
106
0
    return BroadcasterMatchesRef(*broadcaster);
107
0
  return false;
108
0
}
109
110
9
bool SBEvent::BroadcasterMatchesRef(const SBBroadcaster &broadcaster) {
111
9
  LLDB_INSTRUMENT_VA(this, broadcaster);
112
113
9
  Event *lldb_event = get();
114
9
  bool success = false;
115
9
  if (lldb_event)
116
8
    success = lldb_event->BroadcasterIs(broadcaster.get());
117
118
119
9
  return success;
120
9
}
121
122
1
void SBEvent::Clear() {
123
1
  LLDB_INSTRUMENT_VA(this);
124
125
1
  Event *lldb_event = get();
126
1
  if (lldb_event)
127
0
    lldb_event->Clear();
128
1
}
129
130
10
EventSP &SBEvent::GetSP() const { return m_event_sp; }
131
132
496
Event *SBEvent::get() const {
133
  // There is a dangerous accessor call GetSharedPtr which can be used, so if
134
  // we have anything valid in m_event_sp, we must use that since if it gets
135
  // used by a function that puts something in there, then it won't update
136
  // m_opaque_ptr...
137
496
  if (m_event_sp)
138
479
    m_opaque_ptr = m_event_sp.get();
139
140
496
  return m_opaque_ptr;
141
496
}
142
143
196
void SBEvent::reset(EventSP &event_sp) {
144
196
  m_event_sp = event_sp;
145
196
  m_opaque_ptr = m_event_sp.get();
146
196
}
147
148
30
void SBEvent::reset(Event *event_ptr) {
149
30
  m_opaque_ptr = event_ptr;
150
30
  m_event_sp.reset();
151
30
}
152
153
26
bool SBEvent::IsValid() const {
154
26
  LLDB_INSTRUMENT_VA(this);
155
26
  return this->operator bool();
156
26
}
157
30
SBEvent::operator bool() const {
158
30
  LLDB_INSTRUMENT_VA(this);
159
160
  // Do NOT use m_opaque_ptr directly!!! Must use the SBEvent::get() accessor.
161
  // See comments in SBEvent::get()....
162
30
  return SBEvent::get() != nullptr;
163
30
}
164
165
0
const char *SBEvent::GetCStringFromEvent(const SBEvent &event) {
166
0
  LLDB_INSTRUMENT_VA(event);
167
168
0
  return ConstString(static_cast<const char *>(
169
0
                         EventDataBytes::GetBytesFromEvent(event.get())))
170
0
      .GetCString();
171
0
}
172
173
8
bool SBEvent::GetDescription(SBStream &description) {
174
8
  LLDB_INSTRUMENT_VA(this, description);
175
176
8
  Stream &strm = description.ref();
177
178
8
  if (get()) {
179
7
    m_opaque_ptr->Dump(&strm);
180
7
  } else
181
1
    strm.PutCString("No value");
182
183
8
  return true;
184
8
}
185
186
0
bool SBEvent::GetDescription(SBStream &description) const {
187
0
  LLDB_INSTRUMENT_VA(this, description);
188
189
0
  Stream &strm = description.ref();
190
191
0
  if (get()) {
192
0
    m_opaque_ptr->Dump(&strm);
193
0
  } else
194
0
    strm.PutCString("No value");
195
196
0
  return true;
197
0
}