Skip to content

Commit

Permalink
Fix up the "lldb log break" channel output.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jimingham committed Mar 3, 2022
1 parent 94623fb commit 3f43818
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lldb/include/lldb/Breakpoint/Breakpoint.h
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lldb/include/lldb/Utility/Event.h
Expand Up @@ -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:
Expand Down
33 changes: 31 additions & 2 deletions lldb/source/Breakpoint/Breakpoint.cpp
Expand Up @@ -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) {}
Expand All @@ -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;
}

Expand All @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion lldb/source/Utility/Broadcaster.cpp
Expand Up @@ -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,
Expand Down

0 comments on commit 3f43818

Please sign in to comment.