Skip to content

Commit 176d07d

Browse files
authored
[lldb][NFCI] Constrain EventDataBytes creation (#79508)
There are 3 ways to create an EventDataBytes object: (const char *), (llvm::StringRef), and (const void *, size_t len). All of these cases can be handled under `llvm::StringRef`. Additionally, this allows us to remove the otherwise unused `SetBytes`, `SwapBytes`, and `SetBytesFromCString` methods.
1 parent 5f22d33 commit 176d07d

File tree

4 files changed

+8
-45
lines changed

4 files changed

+8
-45
lines changed

lldb/include/lldb/Utility/Event.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ class EventDataBytes : public EventData {
6060
// Constructors
6161
EventDataBytes();
6262

63-
EventDataBytes(const char *cstr);
64-
6563
EventDataBytes(llvm::StringRef str);
6664

67-
EventDataBytes(const void *src, size_t src_len);
68-
6965
~EventDataBytes() override;
7066

7167
// Member functions
@@ -77,12 +73,6 @@ class EventDataBytes : public EventData {
7773

7874
size_t GetByteSize() const;
7975

80-
void SetBytes(const void *src, size_t src_len);
81-
82-
void SwapBytes(std::string &new_bytes);
83-
84-
void SetBytesFromCString(const char *cstr);
85-
8676
// Static functions
8777
static const EventDataBytes *GetEventDataFromEvent(const Event *event_ptr);
8878

lldb/source/API/SBEvent.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ using namespace lldb_private;
2424
SBEvent::SBEvent() { LLDB_INSTRUMENT_VA(this); }
2525

2626
SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
27-
: m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
27+
: m_event_sp(new Event(
28+
event_type, new EventDataBytes(llvm::StringRef(cstr, cstr_len)))),
2829
m_opaque_ptr(m_event_sp.get()) {
2930
LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
3031
}

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,8 @@ Status ProcessGDBRemote::DoAttachToProcessWithID(
10891089
const int packet_len =
10901090
::snprintf(packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid);
10911091
SetID(attach_pid);
1092-
auto data_sp = std::make_shared<EventDataBytes>(packet, packet_len);
1092+
auto data_sp =
1093+
std::make_shared<EventDataBytes>(llvm::StringRef(packet, packet_len));
10931094
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
10941095
} else
10951096
SetExitStatus(-1, error.AsCString());
@@ -1127,8 +1128,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithName(
11271128
endian::InlHostByteOrder(),
11281129
endian::InlHostByteOrder());
11291130
1130-
auto data_sp = std::make_shared<EventDataBytes>(packet.GetString().data(),
1131-
packet.GetSize());
1131+
auto data_sp = std::make_shared<EventDataBytes>(packet.GetString());
11321132
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
11331133
11341134
} else
@@ -1374,8 +1374,8 @@ Status ProcessGDBRemote::DoResume() {
13741374
return error;
13751375
}
13761376
1377-
auto data_sp = std::make_shared<EventDataBytes>(
1378-
continue_packet.GetString().data(), continue_packet.GetSize());
1377+
auto data_sp =
1378+
std::make_shared<EventDataBytes>(continue_packet.GetString());
13791379
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
13801380
13811381
if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) {

lldb/source/Utility/Event.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,7 @@ void EventData::Dump(Stream *s) const { s->PutCString("Generic Event Data"); }
111111

112112
EventDataBytes::EventDataBytes() : m_bytes() {}
113113

114-
EventDataBytes::EventDataBytes(const char *cstr) : m_bytes() {
115-
SetBytesFromCString(cstr);
116-
}
117-
118-
EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes() {
119-
SetBytes(str.data(), str.size());
120-
}
121-
122-
EventDataBytes::EventDataBytes(const void *src, size_t src_len) : m_bytes() {
123-
SetBytes(src, src_len);
124-
}
114+
EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes(str.str()) {}
125115

126116
EventDataBytes::~EventDataBytes() = default;
127117

@@ -147,20 +137,6 @@ const void *EventDataBytes::GetBytes() const {
147137

148138
size_t EventDataBytes::GetByteSize() const { return m_bytes.size(); }
149139

150-
void EventDataBytes::SetBytes(const void *src, size_t src_len) {
151-
if (src != nullptr && src_len > 0)
152-
m_bytes.assign(static_cast<const char *>(src), src_len);
153-
else
154-
m_bytes.clear();
155-
}
156-
157-
void EventDataBytes::SetBytesFromCString(const char *cstr) {
158-
if (cstr != nullptr && cstr[0])
159-
m_bytes.assign(cstr);
160-
else
161-
m_bytes.clear();
162-
}
163-
164140
const void *EventDataBytes::GetBytesFromEvent(const Event *event_ptr) {
165141
const EventDataBytes *e = GetEventDataFromEvent(event_ptr);
166142
if (e != nullptr)
@@ -186,10 +162,6 @@ EventDataBytes::GetEventDataFromEvent(const Event *event_ptr) {
186162
return nullptr;
187163
}
188164

189-
void EventDataBytes::SwapBytes(std::string &new_bytes) {
190-
m_bytes.swap(new_bytes);
191-
}
192-
193165
llvm::StringRef EventDataReceipt::GetFlavorString() {
194166
return "Process::ProcessEventData";
195167
}

0 commit comments

Comments
 (0)