aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2023-02-09 17:24:10 -0800
committerJonas Devlieghere <jonas@devlieghere.com>2023-02-09 21:42:25 -0800
commit125e69015addb656bccaf1c48ea006c9742cda25 (patch)
tree3ae785c65ee166b9f1bc99fe17b78af48cddc107
parentdc4c3cfd78c01bef427fca0431fe66a6c6de7c35 (diff)
downloadllvm-125e69015addb656bccaf1c48ea006c9742cda25.zip
llvm-125e69015addb656bccaf1c48ea006c9742cda25.tar.gz
llvm-125e69015addb656bccaf1c48ea006c9742cda25.tar.bz2
[lldb] Hoist code to create StructuredData into DiagnosticEventData (NFC)
Hoist the code that creates a StructuredData dictionary from a diagnostic event into the DiagnosticEventData. This addresses Ismail's code review feedback from D143687. Differential revision: https://reviews.llvm.org/D143694
-rw-r--r--lldb/include/lldb/Core/DebuggerEvents.h4
-rw-r--r--lldb/source/API/SBDebugger.cpp15
-rw-r--r--lldb/source/Core/DebuggerEvents.cpp16
3 files changed, 25 insertions, 10 deletions
diff --git a/lldb/include/lldb/Core/DebuggerEvents.h b/lldb/include/lldb/Core/DebuggerEvents.h
index f2e23a9..7d22574 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/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 @@ public:
static const DiagnosticEventData *
GetEventDataFromEvent(const Event *event_ptr);
+ static StructuredData::DictionarySP
+ GetAsStructuredData(const Event *event_ptr);
+
protected:
std::string m_message;
Type m_type;
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 851c80a..be86078 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -172,19 +172,14 @@ lldb::SBStructuredData
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_sp =
+ 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_sp)
+ return {};
SBStructuredData data;
- data.m_impl_up->SetObjectSP(std::move(dictionary));
+ data.m_impl_up->SetObjectSP(std::move(dictionary_sp));
return data;
}
diff --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index 6b33af9..6e47da7 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -85,6 +85,22 @@ DiagnosticEventData::GetEventDataFromEvent(const Event *event_ptr) {
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_sp = std::make_shared<StructuredData::Dictionary>();
+ dictionary_sp->AddStringItem("message", diagnostic_data->GetMessage());
+ dictionary_sp->AddStringItem("type", diagnostic_data->GetPrefix());
+ dictionary_sp->AddBooleanItem("debugger_specific",
+ diagnostic_data->IsDebuggerSpecific());
+ return dictionary_sp;
+}
+
ConstString SymbolChangeEventData::GetFlavorString() {
static ConstString g_flavor("SymbolChangeEventData");
return g_flavor;