mib created this revision.
mib added reviewers: jingham, JDevlieghere.
mib added a project: LLDB.
Herald added a project: All.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.
This patch improves the StructuredData classes to provide a
GetDescription(lldb_private::Stream&) affordance.
This is very convenient compared to the Dump method because this try to
pretty print the structure instead of just serializing it into a JSON.
This patch also updates some parts of lldb (i.e. extended crash info) to
use this new affordance instead of StructuredData::Dump.
Signed-off-by: Med Ismail Bennani
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135547
Files:
lldb/include/lldb/Core/StructuredDataImpl.h
lldb/include/lldb/Utility/StructuredData.h
lldb/source/Commands/CommandObjectProcess.cpp
lldb/source/Utility/StructuredData.cpp
Index: lldb/source/Utility/StructuredData.cpp
===
--- lldb/source/Utility/StructuredData.cpp
+++ lldb/source/Utility/StructuredData.cpp
@@ -172,3 +172,62 @@
void StructuredData::Generic::Serialize(json::OStream &s) const {
s.value(llvm::formatv("{0:X}", m_object));
}
+
+void StructuredData::Array::GetDescription(lldb_private::Stream &s) const {
+ s.EOL();
+ s.IndentMore();
+ s.Indent();
+ for (const auto &item_sp : m_items) {
+item_sp->GetDescription(s);
+s.PutChar(',');
+s.EOL();
+ }
+ s.IndentLess();
+ s.EOL();
+ s.Indent();
+}
+
+void StructuredData::Integer::GetDescription(lldb_private::Stream &s) const {
+ printf("%" PRId64, static_cast(m_value));
+}
+
+void StructuredData::Float::GetDescription(lldb_private::Stream &s) const {
+ printf("%f", m_value);
+}
+
+void StructuredData::Boolean::GetDescription(lldb_private::Stream &s) const {
+ s.Printf(m_value ? "True" : "False");
+}
+
+void StructuredData::String::GetDescription(lldb_private::Stream &s) const {
+ s.Printf("%s", m_value.c_str());
+}
+
+void StructuredData::Dictionary::GetDescription(lldb_private::Stream &s) const {
+ s.EOL();
+ s.IndentMore();
+
+ for (const auto &pair : m_dict) {
+if (pair.first.IsNull() || pair.first.IsEmpty() || !pair.second)
+ continue;
+s.Indent();
+s.Printf("%s : ", pair.first.AsCString());
+pair.second->GetDescription(s);
+if (pair != *(--m_dict.end())) {
+ s.PutChar(',');
+ s.EOL();
+}
+ }
+
+ s.IndentLess();
+ s.EOL();
+ s.Indent();
+}
+
+void StructuredData::Null::GetDescription(lldb_private::Stream &s) const {
+ s.Printf("NULL");
+}
+
+void StructuredData::Generic::GetDescription(lldb_private::Stream &s) const {
+ s.Printf("%p", m_object);
+}
Index: lldb/source/Commands/CommandObjectProcess.cpp
===
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -1537,8 +1537,9 @@
StructuredData::DictionarySP crash_info_sp = *expected_crash_info;
if (crash_info_sp) {
+strm.EOL();
strm.PutCString("Extended Crash Information:\n");
-crash_info_sp->Dump(strm);
+crash_info_sp->GetDescription(strm);
}
}
Index: lldb/include/lldb/Utility/StructuredData.h
===
--- lldb/include/lldb/Utility/StructuredData.h
+++ lldb/include/lldb/Utility/StructuredData.h
@@ -158,6 +158,12 @@
Serialize(jso);
}
+virtual void GetDescription(lldb_private::Stream &s) const {
+ s.IndentMore();
+ Dump(s, false);
+ s.IndentLess();
+}
+
private:
lldb::StructuredDataType m_type;
};
@@ -277,6 +283,8 @@
void Serialize(llvm::json::OStream &s) const override;
+void GetDescription(lldb_private::Stream &s) const override;
+
protected:
typedef std::vector collection;
collection m_items;
@@ -295,6 +303,8 @@
void Serialize(llvm::json::OStream &s) const override;
+void GetDescription(lldb_private::Stream &s) const override;
+
protected:
uint64_t m_value;
};
@@ -312,6 +322,8 @@
void Serialize(llvm::json::OStream &s) const override;
+void GetDescription(lldb_private::Stream &s) const override;
+
protected:
double m_value;
};
@@ -329,6 +341,8 @@
void Serialize(llvm::json::OStream &s) const override;
+void GetDescription(lldb_private::Stream &s) const override;
+
protected:
bool m_value;
};
@@ -345,6 +359,8 @@
void Serialize(llvm::json::OStream &s) const override;
+void GetDescription(lldb_private::Stream &s) const override;
+
protected:
std::string m_value;
};
@@ -524,6 +540,8 @@
void Serialize(llvm::json::OStream &s) const override;
+void GetDescription(lldb_private::Stream &s) const override;
+
protected:
typedef std::map collection;
collection m_dict;
@@ -538,6 +556,8 @@
bool IsValid() const override { return false; }
vo