[Lldb-commits] [lldb] 3f43818 - Fix up the "lldb log break" channel output.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 3 12:10:47 PST 2022


Author: Jim Ingham
Date: 2022-03-03T12:10:39-08:00
New Revision: 3f438185a68af4ca99d018d94f4732fd53433674

URL: https://github.com/llvm/llvm-project/commit/3f438185a68af4ca99d018d94f4732fd53433674
DIFF: https://github.com/llvm/llvm-project/commit/3f438185a68af4ca99d018d94f4732fd53433674.diff

LOG: Fix up the "lldb log break" channel output.

1) Make the BreakpointEventData::Dump actually do something useful.
2) Make the Breakpoint events print when the break log channel is on
without having to turn on the events channel.

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

Added: 
    

Modified: 
    lldb/include/lldb/Breakpoint/Breakpoint.h
    lldb/include/lldb/Utility/Event.h
    lldb/source/Breakpoint/Breakpoint.cpp
    lldb/source/Utility/Broadcaster.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Breakpoint/Breakpoint.h b/lldb/include/lldb/Breakpoint/Breakpoint.h
index 113f8c4905e1f..39c6d0b7f3a77 100644
--- a/lldb/include/lldb/Breakpoint/Breakpoint.h
+++ b/lldb/include/lldb/Breakpoint/Breakpoint.h
@@ -81,6 +81,8 @@ class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
                    public Stoppoint {
 public:
   static ConstString GetEventIdentifier();
+  static const char *
+      BreakpointEventTypeAsCString(lldb::BreakpointEventType type);
 
   /// An enum specifying the match style for breakpoint settings.  At present
   /// only used for function name style breakpoints.
@@ -105,12 +107,14 @@ class Breakpoint : public std::enable_shared_from_this<Breakpoint>,
     ~BreakpointEventData() override;
 
     static ConstString GetFlavorString();
+    
+    Log *GetLogChannel() override;
 
     ConstString GetFlavor() const override;
 
     lldb::BreakpointEventType GetBreakpointEventType() const;
 
-    lldb::BreakpointSP &GetBreakpoint();
+    lldb::BreakpointSP GetBreakpoint() const;
 
     BreakpointLocationCollection &GetBreakpointLocationCollection() {
       return m_locations;

diff  --git a/lldb/include/lldb/Utility/Event.h b/lldb/include/lldb/Utility/Event.h
index d3176216115a6..f533fc5c47fa5 100644
--- a/lldb/include/lldb/Utility/Event.h
+++ b/lldb/include/lldb/Utility/Event.h
@@ -42,7 +42,9 @@ class EventData {
   virtual ~EventData();
 
   virtual ConstString GetFlavor() const = 0;
-
+  
+  virtual Log *GetLogChannel() { return nullptr; }
+  
   virtual void Dump(Stream *s) const;
 
 private:

diff  --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp
index 050457986eba6..afadf81e32c8c 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -1010,6 +1010,28 @@ void Breakpoint::SendBreakpointChangedEvent(BreakpointEventData *data) {
     delete data;
 }
 
+const char *Breakpoint::BreakpointEventTypeAsCString(BreakpointEventType type) {
+  switch (type) {
+    case eBreakpointEventTypeInvalidType: return "invalid";
+    case eBreakpointEventTypeAdded: return "breakpoint added";
+    case eBreakpointEventTypeRemoved: return "breakpoint removed";
+    case eBreakpointEventTypeLocationsAdded: return "locations added";
+    case eBreakpointEventTypeLocationsRemoved: return "locations removed";
+    case eBreakpointEventTypeLocationsResolved: return "locations resolved";
+    case eBreakpointEventTypeEnabled: return "breakpoint enabled";
+    case eBreakpointEventTypeDisabled: return "breakpoint disabled";
+    case eBreakpointEventTypeCommandChanged: return "command changed";
+    case eBreakpointEventTypeConditionChanged: return "condition changed";
+    case eBreakpointEventTypeIgnoreChanged: return "ignore count changed";
+    case eBreakpointEventTypeThreadChanged: return "thread changed";
+    case eBreakpointEventTypeAutoContinueChanged: return "autocontinue changed";
+  };
+}
+
+Log *Breakpoint::BreakpointEventData::GetLogChannel() {
+  return GetLog(LLDBLog::Breakpoints);
+}
+
 Breakpoint::BreakpointEventData::BreakpointEventData(
     BreakpointEventType sub_type, const BreakpointSP &new_breakpoint_sp)
     : m_breakpoint_event(sub_type), m_new_breakpoint_sp(new_breakpoint_sp) {}
@@ -1025,7 +1047,7 @@ ConstString Breakpoint::BreakpointEventData::GetFlavor() const {
   return BreakpointEventData::GetFlavorString();
 }
 
-BreakpointSP &Breakpoint::BreakpointEventData::GetBreakpoint() {
+BreakpointSP Breakpoint::BreakpointEventData::GetBreakpoint() const {
   return m_new_breakpoint_sp;
 }
 
@@ -1034,7 +1056,14 @@ Breakpoint::BreakpointEventData::GetBreakpointEventType() const {
   return m_breakpoint_event;
 }
 
-void Breakpoint::BreakpointEventData::Dump(Stream *s) const {}
+void Breakpoint::BreakpointEventData::Dump(Stream *s) const {
+  if (!s)
+    return;
+  BreakpointEventType event_type = GetBreakpointEventType();
+  break_id_t bkpt_id = GetBreakpoint()->GetID();
+  s->Format("bkpt: {0} type: {1}", bkpt_id,
+      BreakpointEventTypeAsCString(event_type));
+}
 
 const Breakpoint::BreakpointEventData *
 Breakpoint::BreakpointEventData::GetEventDataFromEvent(const Event *event) {

diff  --git a/lldb/source/Utility/Broadcaster.cpp b/lldb/source/Utility/Broadcaster.cpp
index bfc26bd4e9182..31530f8a6443d 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -208,7 +208,11 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp,
       hijacking_listener_sp.reset();
   }
 
-  if (Log *log = GetLog(LLDBLog::Events)) {
+  Log *log = GetLog(LLDBLog::Events);
+  if (!log && event_sp->GetData())
+    log = event_sp->GetData()->GetLogChannel();
+
+  if (log) {
     StreamString event_description;
     event_sp->Dump(&event_description);
     LLDB_LOGF(log,


        


More information about the lldb-commits mailing list