Skip to content

[lldb][NFCI] Constrain EventDataBytes creation #79508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions lldb/include/lldb/Utility/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@ class EventDataBytes : public EventData {
// Constructors
EventDataBytes();

EventDataBytes(const char *cstr);

EventDataBytes(llvm::StringRef str);

EventDataBytes(const void *src, size_t src_len);

~EventDataBytes() override;

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

size_t GetByteSize() const;

void SetBytes(const void *src, size_t src_len);

void SwapBytes(std::string &new_bytes);

void SetBytesFromCString(const char *cstr);

// Static functions
static const EventDataBytes *GetEventDataFromEvent(const Event *event_ptr);

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/API/SBEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ using namespace lldb_private;
SBEvent::SBEvent() { LLDB_INSTRUMENT_VA(this); }

SBEvent::SBEvent(uint32_t event_type, const char *cstr, uint32_t cstr_len)
: m_event_sp(new Event(event_type, new EventDataBytes(cstr, cstr_len))),
: m_event_sp(new Event(
event_type, new EventDataBytes(llvm::StringRef(cstr, cstr_len)))),
m_opaque_ptr(m_event_sp.get()) {
LLDB_INSTRUMENT_VA(this, event_type, cstr, cstr_len);
}
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,8 @@ Status ProcessGDBRemote::DoAttachToProcessWithID(
const int packet_len =
::snprintf(packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid);
SetID(attach_pid);
auto data_sp = std::make_shared<EventDataBytes>(packet, packet_len);
auto data_sp =
std::make_shared<EventDataBytes>(llvm::StringRef(packet, packet_len));
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);
} else
SetExitStatus(-1, error.AsCString());
Expand Down Expand Up @@ -1127,8 +1128,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithName(
endian::InlHostByteOrder(),
endian::InlHostByteOrder());

auto data_sp = std::make_shared<EventDataBytes>(packet.GetString().data(),
packet.GetSize());
auto data_sp = std::make_shared<EventDataBytes>(packet.GetString());
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);

} else
Expand Down Expand Up @@ -1374,8 +1374,8 @@ Status ProcessGDBRemote::DoResume() {
return error;
}

auto data_sp = std::make_shared<EventDataBytes>(
continue_packet.GetString().data(), continue_packet.GetSize());
auto data_sp =
std::make_shared<EventDataBytes>(continue_packet.GetString());
m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp);

if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) {
Expand Down
30 changes: 1 addition & 29 deletions lldb/source/Utility/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,7 @@ void EventData::Dump(Stream *s) const { s->PutCString("Generic Event Data"); }

EventDataBytes::EventDataBytes() : m_bytes() {}

EventDataBytes::EventDataBytes(const char *cstr) : m_bytes() {
SetBytesFromCString(cstr);
}

EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes() {
SetBytes(str.data(), str.size());
}

EventDataBytes::EventDataBytes(const void *src, size_t src_len) : m_bytes() {
SetBytes(src, src_len);
}
EventDataBytes::EventDataBytes(llvm::StringRef str) : m_bytes(str.str()) {}

EventDataBytes::~EventDataBytes() = default;

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

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

void EventDataBytes::SetBytes(const void *src, size_t src_len) {
if (src != nullptr && src_len > 0)
m_bytes.assign(static_cast<const char *>(src), src_len);
else
m_bytes.clear();
}

void EventDataBytes::SetBytesFromCString(const char *cstr) {
if (cstr != nullptr && cstr[0])
m_bytes.assign(cstr);
else
m_bytes.clear();
}

const void *EventDataBytes::GetBytesFromEvent(const Event *event_ptr) {
const EventDataBytes *e = GetEventDataFromEvent(event_ptr);
if (e != nullptr)
Expand All @@ -186,10 +162,6 @@ EventDataBytes::GetEventDataFromEvent(const Event *event_ptr) {
return nullptr;
}

void EventDataBytes::SwapBytes(std::string &new_bytes) {
m_bytes.swap(new_bytes);
}

llvm::StringRef EventDataReceipt::GetFlavorString() {
return "Process::ProcessEventData";
}
Expand Down