summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp2
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp4
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h2
-rw-r--r--lldb/source/Utility/StructuredData.cpp100
4 files changed, 29 insertions, 79 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 3f0f3e4bb14..f1762abc55f 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -5089,7 +5089,7 @@ ParseStructuredDataPacket(llvm::StringRef packet) {
if (log) {
if (json_sp) {
StreamString json_str;
- json_sp->Dump(json_str);
+ json_sp->Dump(json_str, true);
json_str.Flush();
LLDB_LOGF(log,
"ProcessGDBRemote::%s() "
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index bb7f77fa514..6d9a74d39cc 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -29,8 +29,8 @@
using namespace lldb_private;
using namespace lldb;
-void StructuredPythonObject::Dump(Stream &s, bool pretty_print) const {
- s << "Python Obj: 0x" << GetValue();
+void StructuredPythonObject::Serialize(llvm::json::OStream &s) const {
+ s.value(llvm::formatv("Python Obj: {0:X}", GetValue()).str());
}
// PythonObject
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 3e1a3541bc7..14484d93148 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -43,7 +43,7 @@ public:
bool IsValid() const override { return GetValue() && GetValue() != Py_None; }
- void Dump(Stream &s, bool pretty_print = true) const override;
+ void Serialize(llvm::json::OStream &s) const override;
private:
DISALLOW_COPY_AND_ASSIGN(StructuredPythonObject);
diff --git a/lldb/source/Utility/StructuredData.cpp b/lldb/source/Utility/StructuredData.cpp
index fde5093428f..b4610702b77 100644
--- a/lldb/source/Utility/StructuredData.cpp
+++ b/lldb/source/Utility/StructuredData.cpp
@@ -11,7 +11,6 @@
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/JSON.h"
#include "lldb/Utility/Status.h"
-#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -21,6 +20,7 @@
#include <limits>
using namespace lldb_private;
+using namespace llvm;
// Functions that use a JSONParser to parse JSON into StructuredData
static StructuredData::ObjectSP ParseJSONValue(JSONParser &json_parser);
@@ -181,98 +181,48 @@ StructuredData::Object::GetObjectForDotSeparatedPath(llvm::StringRef path) {
}
void StructuredData::Object::DumpToStdout(bool pretty_print) const {
- StreamString stream;
- Dump(stream, pretty_print);
- llvm::outs() << stream.GetString();
+ json::OStream stream(llvm::outs(), pretty_print ? 2 : 0);
+ Serialize(stream);
}
-void StructuredData::Array::Dump(Stream &s, bool pretty_print) const {
- bool first = true;
- s << "[";
- if (pretty_print) {
- s << "\n";
- s.IndentMore();
- }
+void StructuredData::Array::Serialize(json::OStream &s) const {
+ s.arrayBegin();
for (const auto &item_sp : m_items) {
- if (first) {
- first = false;
- } else {
- s << ",";
- if (pretty_print)
- s << "\n";
- }
-
- if (pretty_print)
- s.Indent();
- item_sp->Dump(s, pretty_print);
- }
- if (pretty_print) {
- s.IndentLess();
- s.EOL();
- s.Indent();
+ item_sp->Serialize(s);
}
- s << "]";
+ s.arrayEnd();
}
-void StructuredData::Integer::Dump(Stream &s, bool pretty_print) const {
- s.Printf("%" PRIu64, m_value);
+void StructuredData::Integer::Serialize(json::OStream &s) const {
+ s.value(static_cast<int64_t>(m_value));
}
-void StructuredData::Float::Dump(Stream &s, bool pretty_print) const {
- s.Printf("%lg", m_value);
+void StructuredData::Float::Serialize(json::OStream &s) const {
+ s.value(m_value);
}
-void StructuredData::Boolean::Dump(Stream &s, bool pretty_print) const {
- if (m_value)
- s.PutCString("true");
- else
- s.PutCString("false");
+void StructuredData::Boolean::Serialize(json::OStream &s) const {
+ s.value(m_value);
}
-void StructuredData::String::Dump(Stream &s, bool pretty_print) const {
- std::string quoted;
- const size_t strsize = m_value.size();
- for (size_t i = 0; i < strsize; ++i) {
- char ch = m_value[i];
- if (ch == '"' || ch == '\\')
- quoted.push_back('\\');
- quoted.push_back(ch);
- }
- s.Printf("\"%s\"", quoted.c_str());
+void StructuredData::String::Serialize(json::OStream &s) const {
+ s.value(m_value);
}
-void StructuredData::Dictionary::Dump(Stream &s, bool pretty_print) const {
- bool first = true;
- s << "{";
- if (pretty_print) {
- s << "\n";
- s.IndentMore();
- }
+void StructuredData::Dictionary::Serialize(json::OStream &s) const {
+ s.objectBegin();
for (const auto &pair : m_dict) {
- if (first)
- first = false;
- else {
- s << ",";
- if (pretty_print)
- s << "\n";
- }
- if (pretty_print)
- s.Indent();
- s << "\"" << pair.first.AsCString() << "\" : ";
- pair.second->Dump(s, pretty_print);
- }
- if (pretty_print) {
- s.IndentLess();
- s.EOL();
- s.Indent();
+ s.attributeBegin(pair.first.AsCString());
+ pair.second->Serialize(s);
+ s.attributeEnd();
}
- s << "}";
+ s.objectEnd();
}
-void StructuredData::Null::Dump(Stream &s, bool pretty_print) const {
- s << "null";
+void StructuredData::Null::Serialize(json::OStream &s) const {
+ s.value(nullptr);
}
-void StructuredData::Generic::Dump(Stream &s, bool pretty_print) const {
- s << "0x" << m_object;
+void StructuredData::Generic::Serialize(json::OStream &s) const {
+ s.value(llvm::formatv("{0:X}", m_object));
}
OpenPOWER on IntegriCloud