[Lldb-commits] [lldb] 6ebf1bc - [lldb] Change return type of EventData::GetFlavor

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 11 10:52:20 PDT 2023


Author: Alex Langford
Date: 2023-04-11T10:49:17-07:00
New Revision: 6ebf1bc66b898e942f0f483aba200211c6c8ef31

URL: https://github.com/llvm/llvm-project/commit/6ebf1bc66b898e942f0f483aba200211c6c8ef31
DIFF: https://github.com/llvm/llvm-project/commit/6ebf1bc66b898e942f0f483aba200211c6c8ef31.diff

LOG: [lldb] Change return type of EventData::GetFlavor

There's no reason these strings need to be in the ConstString
StringPool, they're already string literals with static lifetime.

I plan on addressing other similar functions in follow up commits.

Differential Revision: https://reviews.llvm.org/D147833

Added: 
    

Modified: 
    lldb/include/lldb/Breakpoint/Breakpoint.h
    lldb/include/lldb/Breakpoint/Watchpoint.h
    lldb/include/lldb/Core/DebuggerEvents.h
    lldb/include/lldb/Target/Process.h
    lldb/include/lldb/Target/Target.h
    lldb/include/lldb/Target/Thread.h
    lldb/include/lldb/Utility/Event.h
    lldb/source/API/SBEvent.cpp
    lldb/source/Breakpoint/Breakpoint.cpp
    lldb/source/Breakpoint/Watchpoint.cpp
    lldb/source/Core/DebuggerEvents.cpp
    lldb/source/Target/Process.cpp
    lldb/source/Target/Target.cpp
    lldb/source/Target/Thread.cpp
    lldb/source/Utility/Event.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Breakpoint/Breakpoint.h b/lldb/include/lldb/Breakpoint/Breakpoint.h
index bd5c377e5014..f2380157f111 100644
--- a/lldb/include/lldb/Breakpoint/Breakpoint.h
+++ b/lldb/include/lldb/Breakpoint/Breakpoint.h
@@ -105,11 +105,11 @@ class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
 
     ~BreakpointEventData() override;
 
-    static ConstString GetFlavorString();
-    
+    static llvm::StringRef GetFlavorString();
+
     Log *GetLogChannel() override;
 
-    ConstString GetFlavor() const override;
+    llvm::StringRef GetFlavor() const override;
 
     lldb::BreakpointEventType GetBreakpointEventType() const;
 

diff  --git a/lldb/include/lldb/Breakpoint/Watchpoint.h b/lldb/include/lldb/Breakpoint/Watchpoint.h
index a5a72e3ad5a1..037be4539066 100644
--- a/lldb/include/lldb/Breakpoint/Watchpoint.h
+++ b/lldb/include/lldb/Breakpoint/Watchpoint.h
@@ -31,9 +31,9 @@ class Watchpoint : public std::enable_shared_from_this<Watchpoint>,
 
     ~WatchpointEventData() override;
 
-    static ConstString GetFlavorString();
+    static llvm::StringRef GetFlavorString();
 
-    ConstString GetFlavor() const override;
+    llvm::StringRef GetFlavor() const override;
 
     lldb::WatchpointEventType GetWatchpointEventType() const;
 

diff  --git a/lldb/include/lldb/Core/DebuggerEvents.h b/lldb/include/lldb/Core/DebuggerEvents.h
index f9ae67efac32..982b22229701 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Core/ModuleSpec.h"
-#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Event.h"
 #include "lldb/Utility/StructuredData.h"
 
@@ -27,9 +26,9 @@ class ProgressEventData : public EventData {
         m_id(progress_id), m_completed(completed), m_total(total),
         m_debugger_specific(debugger_specific) {}
 
-  static ConstString GetFlavorString();
+  static llvm::StringRef GetFlavorString();
 
-  ConstString GetFlavor() const override;
+  llvm::StringRef GetFlavor() const override;
 
   void Dump(Stream *s) const override;
 
@@ -93,8 +92,8 @@ class DiagnosticEventData : public EventData {
 
   void Dump(Stream *s) const override;
 
-  static ConstString GetFlavorString();
-  ConstString GetFlavor() const override;
+  static llvm::StringRef GetFlavorString();
+  llvm::StringRef GetFlavor() const override;
 
   static const DiagnosticEventData *
   GetEventDataFromEvent(const Event *event_ptr);
@@ -116,8 +115,8 @@ class SymbolChangeEventData : public EventData {
   SymbolChangeEventData(lldb::DebuggerWP debugger_wp, ModuleSpec module_spec)
       : m_debugger_wp(debugger_wp), m_module_spec(std::move(module_spec)) {}
 
-  static ConstString GetFlavorString();
-  ConstString GetFlavor() const override;
+  static llvm::StringRef GetFlavorString();
+  llvm::StringRef GetFlavor() const override;
 
   static const SymbolChangeEventData *
   GetEventDataFromEvent(const Event *event_ptr);

diff  --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 1857dd0a7ada..255ba8cd4a92 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -411,9 +411,9 @@ class Process : public std::enable_shared_from_this<Process>,
 
     ~ProcessEventData() override;
 
-    static ConstString GetFlavorString();
+    static llvm::StringRef GetFlavorString();
 
-    ConstString GetFlavor() const override;
+    llvm::StringRef GetFlavor() const override;
 
     lldb::ProcessSP GetProcessSP() const { return m_process_wp.lock(); }
 

diff  --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h
index 7904e78654ef..b322ff7fa37e 100644
--- a/lldb/include/lldb/Target/Target.h
+++ b/lldb/include/lldb/Target/Target.h
@@ -506,9 +506,9 @@ class Target : public std::enable_shared_from_this<Target>,
 
     ~TargetEventData() override;
 
-    static ConstString GetFlavorString();
+    static llvm::StringRef GetFlavorString();
 
-    ConstString GetFlavor() const override {
+    llvm::StringRef GetFlavor() const override {
       return TargetEventData::GetFlavorString();
     }
 

diff  --git a/lldb/include/lldb/Target/Thread.h b/lldb/include/lldb/Target/Thread.h
index 882f001e3af1..95e21c3dc6c7 100644
--- a/lldb/include/lldb/Target/Thread.h
+++ b/lldb/include/lldb/Target/Thread.h
@@ -89,9 +89,9 @@ class Thread : public std::enable_shared_from_this<Thread>,
 
     ~ThreadEventData() override;
 
-    static ConstString GetFlavorString();
+    static llvm::StringRef GetFlavorString();
 
-    ConstString GetFlavor() const override {
+    llvm::StringRef GetFlavor() const override {
       return ThreadEventData::GetFlavorString();
     }
 

diff  --git a/lldb/include/lldb/Utility/Event.h b/lldb/include/lldb/Utility/Event.h
index 8d2d94fe3fdb..72e390dbee89 100644
--- a/lldb/include/lldb/Utility/Event.h
+++ b/lldb/include/lldb/Utility/Event.h
@@ -41,8 +41,8 @@ class EventData {
 
   virtual ~EventData();
 
-  virtual ConstString GetFlavor() const = 0;
-  
+  virtual llvm::StringRef GetFlavor() const = 0;
+
   virtual Log *GetLogChannel() { return nullptr; }
   
   virtual void Dump(Stream *s) const;
@@ -69,7 +69,7 @@ class EventDataBytes : public EventData {
   ~EventDataBytes() override;
 
   // Member functions
-  ConstString GetFlavor() const override;
+  llvm::StringRef GetFlavor() const override;
 
   void Dump(Stream *s) const override;
 
@@ -90,7 +90,7 @@ class EventDataBytes : public EventData {
 
   static size_t GetByteSizeFromEvent(const Event *event_ptr);
 
-  static ConstString GetFlavorString();
+  static llvm::StringRef GetFlavorString();
 
 private:
   std::string m_bytes;
@@ -105,12 +105,9 @@ class EventDataReceipt : public EventData {
 
   ~EventDataReceipt() override = default;
 
-  static ConstString GetFlavorString() {
-    static ConstString g_flavor("Process::ProcessEventData");
-    return g_flavor;
-  }
+  static llvm::StringRef GetFlavorString();
 
-  ConstString GetFlavor() const override { return GetFlavorString(); }
+  llvm::StringRef GetFlavor() const override { return GetFlavorString(); }
 
   bool WaitForEventReceived(const Timeout<std::micro> &timeout = std::nullopt) {
     return m_predicate.WaitForValueEqualTo(true, timeout);
@@ -139,7 +136,7 @@ class EventDataStructuredData : public EventData {
   ~EventDataStructuredData() override;
 
   // Member functions
-  ConstString GetFlavor() const override;
+  llvm::StringRef GetFlavor() const override;
 
   void Dump(Stream *s) const override;
 
@@ -166,7 +163,7 @@ class EventDataStructuredData : public EventData {
   static lldb::StructuredDataPluginSP
   GetPluginFromEvent(const Event *event_ptr);
 
-  static ConstString GetFlavorString();
+  static llvm::StringRef GetFlavorString();
 
 private:
   lldb::ProcessSP m_process_sp;

diff  --git a/lldb/source/API/SBEvent.cpp b/lldb/source/API/SBEvent.cpp
index 536680bd1c5e..d4ea0430f163 100644
--- a/lldb/source/API/SBEvent.cpp
+++ b/lldb/source/API/SBEvent.cpp
@@ -63,7 +63,7 @@ const char *SBEvent::GetDataFlavor() {
   if (lldb_event) {
     EventData *event_data = lldb_event->GetData();
     if (event_data)
-      return lldb_event->GetData()->GetFlavor().AsCString();
+      return lldb_event->GetData()->GetFlavor().data();
   }
   return nullptr;
 }

diff  --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp
index 9a2dbc0c143f..54ac21ac9e48 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -1039,12 +1039,11 @@ Breakpoint::BreakpointEventData::BreakpointEventData(
 
 Breakpoint::BreakpointEventData::~BreakpointEventData() = default;
 
-ConstString Breakpoint::BreakpointEventData::GetFlavorString() {
-  static ConstString g_flavor("Breakpoint::BreakpointEventData");
-  return g_flavor;
+llvm::StringRef Breakpoint::BreakpointEventData::GetFlavorString() {
+  return "Breakpoint::BreakpointEventData";
 }
 
-ConstString Breakpoint::BreakpointEventData::GetFlavor() const {
+llvm::StringRef Breakpoint::BreakpointEventData::GetFlavor() const {
   return BreakpointEventData::GetFlavorString();
 }
 

diff  --git a/lldb/source/Breakpoint/Watchpoint.cpp b/lldb/source/Breakpoint/Watchpoint.cpp
index 0ad3498dac54..d8b8bd505db9 100644
--- a/lldb/source/Breakpoint/Watchpoint.cpp
+++ b/lldb/source/Breakpoint/Watchpoint.cpp
@@ -337,12 +337,11 @@ Watchpoint::WatchpointEventData::WatchpointEventData(
 
 Watchpoint::WatchpointEventData::~WatchpointEventData() = default;
 
-ConstString Watchpoint::WatchpointEventData::GetFlavorString() {
-  static ConstString g_flavor("Watchpoint::WatchpointEventData");
-  return g_flavor;
+llvm::StringRef Watchpoint::WatchpointEventData::GetFlavorString() {
+  return "Watchpoint::WatchpointEventData";
 }
 
-ConstString Watchpoint::WatchpointEventData::GetFlavor() const {
+llvm::StringRef Watchpoint::WatchpointEventData::GetFlavor() const {
   return WatchpointEventData::GetFlavorString();
 }
 

diff  --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index 1c38e9bbc22f..dd77fff349a6 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -23,12 +23,11 @@ static const T *GetEventDataFromEventImpl(const Event *event_ptr) {
   return nullptr;
 }
 
-ConstString ProgressEventData::GetFlavorString() {
-  static ConstString g_flavor("ProgressEventData");
-  return g_flavor;
+llvm::StringRef ProgressEventData::GetFlavorString() {
+  return "ProgressEventData";
 }
 
-ConstString ProgressEventData::GetFlavor() const {
+llvm::StringRef ProgressEventData::GetFlavor() const {
   return ProgressEventData::GetFlavorString();
 }
 
@@ -94,12 +93,11 @@ void DiagnosticEventData::Dump(Stream *s) const {
   s->Flush();
 }
 
-ConstString DiagnosticEventData::GetFlavorString() {
-  static ConstString g_flavor("DiagnosticEventData");
-  return g_flavor;
+llvm::StringRef DiagnosticEventData::GetFlavorString() {
+  return "DiagnosticEventData";
 }
 
-ConstString DiagnosticEventData::GetFlavor() const {
+llvm::StringRef DiagnosticEventData::GetFlavor() const {
   return DiagnosticEventData::GetFlavorString();
 }
 
@@ -124,12 +122,11 @@ DiagnosticEventData::GetAsStructuredData(const Event *event_ptr) {
   return dictionary_sp;
 }
 
-ConstString SymbolChangeEventData::GetFlavorString() {
-  static ConstString g_flavor("SymbolChangeEventData");
-  return g_flavor;
+llvm::StringRef SymbolChangeEventData::GetFlavorString() {
+  return "SymbolChangeEventData";
 }
 
-ConstString SymbolChangeEventData::GetFlavor() const {
+llvm::StringRef SymbolChangeEventData::GetFlavor() const {
   return SymbolChangeEventData::GetFlavorString();
 }
 

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 77ee27687fef..af5b0d092010 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -3929,12 +3929,11 @@ Process::ProcessEventData::ProcessEventData(const ProcessSP &process_sp,
 
 Process::ProcessEventData::~ProcessEventData() = default;
 
-ConstString Process::ProcessEventData::GetFlavorString() {
-  static ConstString g_flavor("Process::ProcessEventData");
-  return g_flavor;
+llvm::StringRef Process::ProcessEventData::GetFlavorString() {
+  return "Process::ProcessEventData";
 }
 
-ConstString Process::ProcessEventData::GetFlavor() const {
+llvm::StringRef Process::ProcessEventData::GetFlavor() const {
   return ProcessEventData::GetFlavorString();
 }
 

diff  --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 40d67246c8e8..bda896625d5f 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -4786,9 +4786,8 @@ Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp,
 
 Target::TargetEventData::~TargetEventData() = default;
 
-ConstString Target::TargetEventData::GetFlavorString() {
-  static ConstString g_flavor("Target::TargetEventData");
-  return g_flavor;
+llvm::StringRef Target::TargetEventData::GetFlavorString() {
+  return "Target::TargetEventData";
 }
 
 void Target::TargetEventData::Dump(Stream *s) const {

diff  --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index ab8c115c2d96..d53eed3697e5 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -150,9 +150,8 @@ uint64_t ThreadProperties::GetMaxBacktraceDepth() const {
 
 // Thread Event Data
 
-ConstString Thread::ThreadEventData::GetFlavorString() {
-  static ConstString g_flavor("Thread::ThreadEventData");
-  return g_flavor;
+llvm::StringRef Thread::ThreadEventData::GetFlavorString() {
+  return "Thread::ThreadEventData";
 }
 
 Thread::ThreadEventData::ThreadEventData(const lldb::ThreadSP thread_sp)

diff  --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp
index 5fca61b16df8..291e19173604 100644
--- a/lldb/source/Utility/Event.cpp
+++ b/lldb/source/Utility/Event.cpp
@@ -114,12 +114,9 @@ EventDataBytes::EventDataBytes(const void *src, size_t src_len) : m_bytes() {
 
 EventDataBytes::~EventDataBytes() = default;
 
-ConstString EventDataBytes::GetFlavorString() {
-  static ConstString g_flavor("EventDataBytes");
-  return g_flavor;
-}
+llvm::StringRef EventDataBytes::GetFlavorString() { return "EventDataBytes"; }
 
-ConstString EventDataBytes::GetFlavor() const {
+llvm::StringRef EventDataBytes::GetFlavor() const {
   return EventDataBytes::GetFlavorString();
 }
 
@@ -182,6 +179,10 @@ void EventDataBytes::SwapBytes(std::string &new_bytes) {
   m_bytes.swap(new_bytes);
 }
 
+llvm::StringRef EventDataReceipt::GetFlavorString() {
+  return "Process::ProcessEventData";
+}
+
 #pragma mark -
 #pragma mark EventStructuredData
 
@@ -200,7 +201,7 @@ EventDataStructuredData::~EventDataStructuredData() = default;
 
 // EventDataStructuredData member functions
 
-ConstString EventDataStructuredData::GetFlavor() const {
+llvm::StringRef EventDataStructuredData::GetFlavor() const {
   return EventDataStructuredData::GetFlavorString();
 }
 
@@ -280,7 +281,6 @@ EventDataStructuredData::GetPluginFromEvent(const Event *event_ptr) {
     return StructuredDataPluginSP();
 }
 
-ConstString EventDataStructuredData::GetFlavorString() {
-  static ConstString s_flavor("EventDataStructuredData");
-  return s_flavor;
+llvm::StringRef EventDataStructuredData::GetFlavorString() {
+  return "EventDataStructuredData";
 }


        


More information about the lldb-commits mailing list