From 867ee3b8a76a78e02c56e78382e31bfd76fa468b Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Mon, 5 Jun 2023 18:05:11 -0700 Subject: [PATCH] [lldb][NFCI] Change type of Broadcaster's name Broadcasters don't need their names in the StringPool. It doesn't benefit from fast comparisons and doesn't benefit from uniqueness. Differential Revision: https://reviews.llvm.org/D152220 --- lldb/include/lldb/Utility/Broadcaster.h | 21 ++++++++++++--------- lldb/source/API/SBBroadcaster.cpp | 2 +- lldb/source/Core/ThreadedCommunication.cpp | 2 +- lldb/source/Utility/Broadcaster.cpp | 16 ++++++++-------- lldb/source/Utility/Event.cpp | 4 ++-- lldb/source/Utility/Listener.cpp | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/lldb/include/lldb/Utility/Broadcaster.h b/lldb/include/lldb/Utility/Broadcaster.h index 081e6ee..f988756 100644 --- a/lldb/include/lldb/Utility/Broadcaster.h +++ b/lldb/include/lldb/Utility/Broadcaster.h @@ -149,10 +149,12 @@ class Broadcaster { public: /// Construct with a broadcaster with a name. /// + /// \param[in] manager_sp + /// A shared pointer to the BroadcasterManager that will manage this + /// broadcaster. /// \param[in] name - /// A NULL terminated C string that contains the name of the - /// broadcaster object. - Broadcaster(lldb::BroadcasterManagerSP manager_sp, const char *name); + /// A std::string of the name that this broadcaster will have. + Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name); /// Destructor. /// @@ -213,11 +215,12 @@ public: return m_broadcaster_sp->AddListener(listener_sp, event_mask); } - /// Get the NULL terminated C string name of this Broadcaster object. + /// Get this broadcaster's name. /// /// \return - /// The NULL terminated C string name of this Broadcaster. - ConstString GetBroadcasterName() { return m_broadcaster_name; } + /// A reference to a constant std::string containing the name of the + /// broadcaster. + const std::string &GetBroadcasterName() { return m_broadcaster_name; } /// Get the event name(s) for one or more event bits. /// @@ -352,8 +355,8 @@ protected: uint32_t AddListener(const lldb::ListenerSP &listener_sp, uint32_t event_mask); - const char *GetBroadcasterName() const { - return m_broadcaster.GetBroadcasterName().AsCString(); + const std::string &GetBroadcasterName() const { + return m_broadcaster.GetBroadcasterName(); } Broadcaster *GetBroadcaster(); @@ -443,7 +446,7 @@ private: lldb::BroadcasterManagerSP m_manager_sp; /// The name of this broadcaster object. - const ConstString m_broadcaster_name; + const std::string m_broadcaster_name; Broadcaster(const Broadcaster &) = delete; const Broadcaster &operator=(const Broadcaster &) = delete; diff --git a/lldb/source/API/SBBroadcaster.cpp b/lldb/source/API/SBBroadcaster.cpp index 5892093..6e34b2f 100644 --- a/lldb/source/API/SBBroadcaster.cpp +++ b/lldb/source/API/SBBroadcaster.cpp @@ -92,7 +92,7 @@ const char *SBBroadcaster::GetName() const { LLDB_INSTRUMENT_VA(this); if (m_opaque_ptr) - return m_opaque_ptr->GetBroadcasterName().GetCString(); + return ConstString(m_opaque_ptr->GetBroadcasterName()).GetCString(); return nullptr; } diff --git a/lldb/source/Core/ThreadedCommunication.cpp b/lldb/source/Core/ThreadedCommunication.cpp index d547c85..ec4b080 100644 --- a/lldb/source/Core/ThreadedCommunication.cpp +++ b/lldb/source/Core/ThreadedCommunication.cpp @@ -57,7 +57,7 @@ ThreadedCommunication::ThreadedCommunication(const char *name) ThreadedCommunication::~ThreadedCommunication() { LLDB_LOG(GetLog(LLDBLog::Object | LLDBLog::Communication), "{0} ThreadedCommunication::~ThreadedCommunication (name = {1})", - this, GetBroadcasterName().AsCString()); + this, GetBroadcasterName()); } void ThreadedCommunication::Clear() { diff --git a/lldb/source/Utility/Broadcaster.cpp b/lldb/source/Utility/Broadcaster.cpp index 58e3938..c9ecd4a 100644 --- a/lldb/source/Utility/Broadcaster.cpp +++ b/lldb/source/Utility/Broadcaster.cpp @@ -23,9 +23,9 @@ using namespace lldb; using namespace lldb_private; -Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name) +Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, std::string name) : m_broadcaster_sp(std::make_shared(*this)), - m_manager_sp(std::move(manager_sp)), m_broadcaster_name(name) { + m_manager_sp(std::move(manager_sp)), m_broadcaster_name(std::move(name)) { Log *log = GetLog(LLDBLog::Object); LLDB_LOG(log, "{0} Broadcaster::Broadcaster(\"{1}\")", static_cast(this), GetBroadcasterName()); @@ -215,12 +215,12 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp, if (log) { StreamString event_description; event_sp->Dump(&event_description); - LLDB_LOGF(log, - "%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, " - "unique =%i) hijack = %p", - static_cast(this), GetBroadcasterName(), - event_description.GetData(), unique, - static_cast(hijacking_listener_sp.get())); + LLDB_LOG(log, + "{0:x} Broadcaster(\"{1}\")::BroadcastEvent (event_sp = {2}, " + "unique={3}) hijack = {4:x}", + static_cast(this), GetBroadcasterName(), + event_description.GetData(), unique, + static_cast(hijacking_listener_sp.get())); } if (hijacking_listener_sp) { diff --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp index 291e191..efab760 100644 --- a/lldb/source/Utility/Event.cpp +++ b/lldb/source/Utility/Event.cpp @@ -58,13 +58,13 @@ void Event::Dump(Stream *s) const { s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x (%s), data = ", static_cast(this), static_cast(broadcaster), - broadcaster->GetBroadcasterName().GetCString(), m_type, + broadcaster->GetBroadcasterName().c_str(), m_type, event_name.GetData()); else s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x, data = ", static_cast(this), static_cast(broadcaster), - broadcaster->GetBroadcasterName().GetCString(), m_type); + broadcaster->GetBroadcasterName().c_str(), m_type); } else s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ", static_cast(this), m_type); diff --git a/lldb/source/Utility/Listener.cpp b/lldb/source/Utility/Listener.cpp index 2286827..060fc2b 100644 --- a/lldb/source/Utility/Listener.cpp +++ b/lldb/source/Utility/Listener.cpp @@ -234,7 +234,7 @@ public: if (m_broadcaster_names) { bool found_source = false; - ConstString event_broadcaster_name = + const llvm::StringRef event_broadcaster_name = event_sp->GetBroadcaster()->GetBroadcasterName(); for (uint32_t i = 0; i < m_num_broadcaster_names; ++i) { if (m_broadcaster_names[i] == event_broadcaster_name) { -- 2.7.4