[Lldb-commits] [PATCH] D143694: [lldb] Hoist code to create StructuredData into DiagnosticEventData (NFC)

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 9 21:42:38 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG125e69015add: [lldb] Hoist code to create StructuredData into DiagnosticEventData (NFC) (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D143694?vs=496289&id=496328#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143694/new/

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_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;
Index: lldb/source/API/SBDebugger.cpp
===================================================================
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -172,19 +172,14 @@
 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;
 }
 
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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143694.496328.patch
Type: text/x-patch
Size: 2779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230210/8712a11a/attachment.bin>


More information about the lldb-commits mailing list