Skip to content

Commit 125e690

Browse files
committed
[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
1 parent dc4c3cf commit 125e690

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Core/ModuleSpec.h"
1010
#include "lldb/Utility/ConstString.h"
1111
#include "lldb/Utility/Event.h"
12+
#include "lldb/Utility/StructuredData.h"
1213

1314
#include <string>
1415

@@ -75,6 +76,9 @@ class DiagnosticEventData : public EventData {
7576
static const DiagnosticEventData *
7677
GetEventDataFromEvent(const Event *event_ptr);
7778

79+
static StructuredData::DictionarySP
80+
GetAsStructuredData(const Event *event_ptr);
81+
7882
protected:
7983
std::string m_message;
8084
Type m_type;

lldb/source/API/SBDebugger.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,14 @@ lldb::SBStructuredData
172172
SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) {
173173
LLDB_INSTRUMENT_VA(event);
174174

175-
const DiagnosticEventData *diagnostic_data =
176-
DiagnosticEventData::GetEventDataFromEvent(event.get());
177-
if (!diagnostic_data)
178-
return {};
175+
StructuredData::DictionarySP dictionary_sp =
176+
DiagnosticEventData::GetAsStructuredData(event.get());
179177

180-
auto dictionary = std::make_unique<StructuredData::Dictionary>();
181-
dictionary->AddStringItem("message", diagnostic_data->GetMessage());
182-
dictionary->AddStringItem("type", diagnostic_data->GetPrefix());
183-
dictionary->AddBooleanItem("debugger_specific",
184-
diagnostic_data->IsDebuggerSpecific());
178+
if (!dictionary_sp)
179+
return {};
185180

186181
SBStructuredData data;
187-
data.m_impl_up->SetObjectSP(std::move(dictionary));
182+
data.m_impl_up->SetObjectSP(std::move(dictionary_sp));
188183
return data;
189184
}
190185

lldb/source/Core/DebuggerEvents.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ DiagnosticEventData::GetEventDataFromEvent(const Event *event_ptr) {
8585
return GetEventDataFromEventImpl<DiagnosticEventData>(event_ptr);
8686
}
8787

88+
StructuredData::DictionarySP
89+
DiagnosticEventData::GetAsStructuredData(const Event *event_ptr) {
90+
const DiagnosticEventData *diagnostic_data =
91+
DiagnosticEventData::GetEventDataFromEvent(event_ptr);
92+
93+
if (!diagnostic_data)
94+
return {};
95+
96+
auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();
97+
dictionary_sp->AddStringItem("message", diagnostic_data->GetMessage());
98+
dictionary_sp->AddStringItem("type", diagnostic_data->GetPrefix());
99+
dictionary_sp->AddBooleanItem("debugger_specific",
100+
diagnostic_data->IsDebuggerSpecific());
101+
return dictionary_sp;
102+
}
103+
88104
ConstString SymbolChangeEventData::GetFlavorString() {
89105
static ConstString g_flavor("SymbolChangeEventData");
90106
return g_flavor;

0 commit comments

Comments
 (0)