JDevlieghere created this revision. JDevlieghere added a reviewer: mib. Herald added a project: All. JDevlieghere requested review of this revision.
Hoist the code that creates a StructuredData dictionary from a diagnostic event into the DiagnosticEventData. This addresses Ismail's code review feedback from D143687 <https://reviews.llvm.org/D143687>. https://reviews.llvm.org/D143694 Files: lldb/include/lldb/Core/DebuggerEvents.h lldb/source/API/SBDebugger.cpp lldb/source/Core/DebuggerEvents.cpp Index: lldb/source/Core/DebuggerEvents.cpp =================================================================== --- lldb/source/Core/DebuggerEvents.cpp +++ lldb/source/Core/DebuggerEvents.cpp @@ -85,6 +85,22 @@ return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr); } +StructuredData::DictionarySP +DiagnosticEventData::GetAsStructuredData(const Event *event_ptr) { + const DiagnosticEventData *diagnostic_data = + DiagnosticEventData::GetEventDataFromEvent(event_ptr); + + if (!diagnostic_data) + return {}; + + auto dictionary = std::make_shared<StructuredData::Dictionary>(); + dictionary->AddStringItem("message", diagnostic_data->GetMessage()); + dictionary->AddStringItem("type", diagnostic_data->GetPrefix()); + dictionary->AddBooleanItem("debugger_specific", + diagnostic_data->IsDebuggerSpecific()); + return dictionary; +} + ConstString SymbolChangeEventData::GetFlavorString() { static ConstString g_flavor("SymbolChangeEventData"); return g_flavor; Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -172,16 +172,11 @@ SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) { LLDB_INSTRUMENT_VA(event); - const DiagnosticEventData *diagnostic_data = - DiagnosticEventData::GetEventDataFromEvent(event.get()); - if (!diagnostic_data) - return {}; + StructuredData::DictionarySP dictionary = + DiagnosticEventData::GetAsStructuredData(event.get()); - auto dictionary = std::make_unique<StructuredData::Dictionary>(); - dictionary->AddStringItem("message", diagnostic_data->GetMessage()); - dictionary->AddStringItem("type", diagnostic_data->GetPrefix()); - dictionary->AddBooleanItem("debugger_specific", - diagnostic_data->IsDebuggerSpecific()); + if (!dictionary) + return {}; SBStructuredData data; data.m_impl_up->SetObjectSP(std::move(dictionary)); Index: lldb/include/lldb/Core/DebuggerEvents.h =================================================================== --- lldb/include/lldb/Core/DebuggerEvents.h +++ lldb/include/lldb/Core/DebuggerEvents.h @@ -9,6 +9,7 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Event.h" +#include "lldb/Utility/StructuredData.h" #include <string> @@ -75,6 +76,9 @@ static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr); + static StructuredData::DictionarySP + GetAsStructuredData(const Event *event_ptr); + protected: std::string m_message; Type m_type;
Index: lldb/source/Core/DebuggerEvents.cpp =================================================================== --- lldb/source/Core/DebuggerEvents.cpp +++ lldb/source/Core/DebuggerEvents.cpp @@ -85,6 +85,22 @@ return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr); } +StructuredData::DictionarySP +DiagnosticEventData::GetAsStructuredData(const Event *event_ptr) { + const DiagnosticEventData *diagnostic_data = + DiagnosticEventData::GetEventDataFromEvent(event_ptr); + + if (!diagnostic_data) + return {}; + + auto dictionary = std::make_shared<StructuredData::Dictionary>(); + dictionary->AddStringItem("message", diagnostic_data->GetMessage()); + dictionary->AddStringItem("type", diagnostic_data->GetPrefix()); + dictionary->AddBooleanItem("debugger_specific", + diagnostic_data->IsDebuggerSpecific()); + return dictionary; +} + ConstString SymbolChangeEventData::GetFlavorString() { static ConstString g_flavor("SymbolChangeEventData"); return g_flavor; Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -172,16 +172,11 @@ SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) { LLDB_INSTRUMENT_VA(event); - const DiagnosticEventData *diagnostic_data = - DiagnosticEventData::GetEventDataFromEvent(event.get()); - if (!diagnostic_data) - return {}; + StructuredData::DictionarySP dictionary = + DiagnosticEventData::GetAsStructuredData(event.get()); - auto dictionary = std::make_unique<StructuredData::Dictionary>(); - dictionary->AddStringItem("message", diagnostic_data->GetMessage()); - dictionary->AddStringItem("type", diagnostic_data->GetPrefix()); - dictionary->AddBooleanItem("debugger_specific", - diagnostic_data->IsDebuggerSpecific()); + if (!dictionary) + return {}; SBStructuredData data; data.m_impl_up->SetObjectSP(std::move(dictionary)); Index: lldb/include/lldb/Core/DebuggerEvents.h =================================================================== --- lldb/include/lldb/Core/DebuggerEvents.h +++ lldb/include/lldb/Core/DebuggerEvents.h @@ -9,6 +9,7 @@ #include "lldb/Core/ModuleSpec.h" #include "lldb/Utility/ConstString.h" #include "lldb/Utility/Event.h" +#include "lldb/Utility/StructuredData.h" #include <string> @@ -75,6 +76,9 @@ static const DiagnosticEventData * GetEventDataFromEvent(const Event *event_ptr); + static StructuredData::DictionarySP + GetAsStructuredData(const Event *event_ptr); + protected: std::string m_message; Type m_type;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits