This is the main part of a change to add breakpoint save and restore to lldb.
Still to come:
1) SB API's
2) Testcases
3) Loose ends:
a) serialize Thread options
b) serialize Exception resolvers
4) "break list --file" should list breakpoints contained in a file and
"break read -f 1 3 5" should then read in only those breakpoints.
<rdar://problem/12611863>
llvm-svn: 281273
diff --git a/lldb/source/Core/StructuredData.cpp b/lldb/source/Core/StructuredData.cpp
index 6e544c1..5980e0f 100644
--- a/lldb/source/Core/StructuredData.cpp
+++ b/lldb/source/Core/StructuredData.cpp
@@ -14,7 +14,11 @@
#include <inttypes.h>
#include <stdlib.h>
+#include "lldb/Core/DataBuffer.h"
+#include "lldb/Core/Error.h"
#include "lldb/Core/StreamString.h"
+#include "lldb/Host/File.h"
+#include "lldb/Host/FileSpec.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/JSON.h"
@@ -27,6 +31,44 @@
static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser);
static StructuredData::ObjectSP ParseJSONArray(JSONParser &json_parser);
+StructuredData::ObjectSP StructuredData::ParseJSONFromFile(FileSpec &input_spec,
+ Error &error) {
+ StructuredData::ObjectSP return_sp;
+ if (!input_spec.Exists()) {
+ error.SetErrorStringWithFormat("input file %s does not exist.",
+ input_spec.GetPath().c_str());
+ return return_sp;
+ }
+
+ File input_file(nullptr, File::OpenOptions::eOpenOptionRead,
+ lldb::eFilePermissionsUserRead);
+ std::string input_path = input_spec.GetPath();
+ error =
+ input_file.Open(input_path.c_str(), File::OpenOptions::eOpenOptionRead,
+ lldb::eFilePermissionsUserRead);
+
+ if (!error.Success()) {
+ error.SetErrorStringWithFormat("could not open input file: %s - %s.",
+ input_spec.GetPath().c_str(),
+ error.AsCString());
+ return return_sp;
+ }
+
+ lldb::DataBufferSP input_data;
+ size_t num_bytes = SIZE_T_MAX;
+ off_t offset = 0;
+ error = input_file.Read(num_bytes, offset, true, input_data);
+ if (!error.Success()) {
+ error.SetErrorStringWithFormat("could not read input file: %s - %s.",
+ input_spec.GetPath().c_str(),
+ error.AsCString());
+ return return_sp;
+ }
+ JSONParser json_parser((char *)input_data->GetBytes());
+ return_sp = ParseJSONValue(json_parser);
+ return return_sp;
+}
+
static StructuredData::ObjectSP ParseJSONObject(JSONParser &json_parser) {
// The "JSONParser::Token::ObjectStart" token should have already been
// consumed