[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)
https://github.com/bulbazord closed https://github.com/llvm/llvm-project/pull/79508 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)
jimingham wrote: LGTM This code was originally written before we used StringRef's, so making that conversion complete is good. https://github.com/llvm/llvm-project/pull/79508 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)
https://github.com/JDevlieghere approved this pull request. https://github.com/llvm/llvm-project/pull/79508 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Alex Langford (bulbazord) Changes 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. --- Full diff: https://github.com/llvm/llvm-project/pull/79508.diff 4 Files Affected: - (modified) lldb/include/lldb/Utility/Event.h (-10) - (modified) lldb/source/API/SBEvent.cpp (+2-1) - (modified) lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (+5-5) - (modified) lldb/source/Utility/Event.cpp (+1-29) ``diff diff --git a/lldb/include/lldb/Utility/Event.h b/lldb/include/lldb/Utility/Event.h index 3de0401191caa7f..461d711b8c3f2c4 100644 --- a/lldb/include/lldb/Utility/Event.h +++ b/lldb/include/lldb/Utility/Event.h @@ -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 @@ -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 _bytes); - - void SetBytesFromCString(const char *cstr); - // Static functions static const EventDataBytes *GetEventDataFromEvent(const Event *event_ptr); diff --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp index f12df2939420d63..cc611449e25099a 100644 --- a/lldb/source/API/SBEvent.cpp +++ b/lldb/source/API/SBEvent.cpp @@ -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); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index eb42b9eb6cb6a57..4a06027501a898b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -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(packet, packet_len); + auto data_sp = + std::make_shared(llvm::StringRef(packet, packet_len)); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp); } else SetExitStatus(-1, error.AsCString()); @@ -1127,8 +1128,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithName( endian::InlHostByteOrder(), endian::InlHostByteOrder()); - auto data_sp = std::make_shared(packet.GetString().data(), - packet.GetSize()); + auto data_sp = std::make_shared(packet.GetString()); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp); } else @@ -1374,8 +1374,8 @@ Status ProcessGDBRemote::DoResume() { return error; } - auto data_sp = std::make_shared( - continue_packet.GetString().data(), continue_packet.GetSize()); + auto data_sp = + std::make_shared(continue_packet.GetString()); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp); if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) { diff --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp index cac118182c75da3..863167e56bce6f5 100644 --- a/lldb/source/Utility/Event.cpp +++ b/lldb/source/Utility/Event.cpp @@ -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; @@ -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 &&
[Lldb-commits] [lldb] [lldb][NFCI] Constrain EventDataBytes creation (PR #79508)
https://github.com/bulbazord created https://github.com/llvm/llvm-project/pull/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. >From 670abd2507ee45258801a759646b475a0db8e49c Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Thu, 25 Jan 2024 13:45:24 -0800 Subject: [PATCH] [lldb][NFCI] Constrain EventDataBytes creation 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. --- lldb/include/lldb/Utility/Event.h | 10 --- lldb/source/API/SBEvent.cpp | 3 +- .../Process/gdb-remote/ProcessGDBRemote.cpp | 10 +++ lldb/source/Utility/Event.cpp | 30 +-- 4 files changed, 8 insertions(+), 45 deletions(-) diff --git a/lldb/include/lldb/Utility/Event.h b/lldb/include/lldb/Utility/Event.h index 3de0401191caa7..461d711b8c3f2c 100644 --- a/lldb/include/lldb/Utility/Event.h +++ b/lldb/include/lldb/Utility/Event.h @@ -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 @@ -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 _bytes); - - void SetBytesFromCString(const char *cstr); - // Static functions static const EventDataBytes *GetEventDataFromEvent(const Event *event_ptr); diff --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp index f12df2939420d6..cc611449e25099 100644 --- a/lldb/source/API/SBEvent.cpp +++ b/lldb/source/API/SBEvent.cpp @@ -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); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index eb42b9eb6cb6a5..4a06027501a898 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -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(packet, packet_len); + auto data_sp = + std::make_shared(llvm::StringRef(packet, packet_len)); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp); } else SetExitStatus(-1, error.AsCString()); @@ -1127,8 +1128,7 @@ Status ProcessGDBRemote::DoAttachToProcessWithName( endian::InlHostByteOrder(), endian::InlHostByteOrder()); - auto data_sp = std::make_shared(packet.GetString().data(), - packet.GetSize()); + auto data_sp = std::make_shared(packet.GetString()); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp); } else @@ -1374,8 +1374,8 @@ Status ProcessGDBRemote::DoResume() { return error; } - auto data_sp = std::make_shared( - continue_packet.GetString().data(), continue_packet.GetSize()); + auto data_sp = + std::make_shared(continue_packet.GetString()); m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue, data_sp); if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) { diff --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp index cac118182c75da..863167e56bce6f 100644 --- a/lldb/source/Utility/Event.cpp +++ b/lldb/source/Utility/Event.cpp @@ -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()); -} -