summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/StructuredData.cpp
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2016-09-12 23:10:56 +0000
committerJim Ingham <jingham@apple.com>2016-09-12 23:10:56 +0000
commite14dc26857470f248e5fc1dd14d89314eae47fa5 (patch)
tree4233b63c194167caeb8d013fa04bbbb88441b55d /lldb/source/Core/StructuredData.cpp
parent9db7948e90133938079bc9bdb02b16cfd22f0015 (diff)
downloadbcm5719-llvm-e14dc26857470f248e5fc1dd14d89314eae47fa5.tar.gz
bcm5719-llvm-e14dc26857470f248e5fc1dd14d89314eae47fa5.zip
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
Diffstat (limited to 'lldb/source/Core/StructuredData.cpp')
-rw-r--r--lldb/source/Core/StructuredData.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/lldb/source/Core/StructuredData.cpp b/lldb/source/Core/StructuredData.cpp
index 6e544c1d537..5980e0fe645 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 ParseJSONValue(JSONParser &json_parser);
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
OpenPOWER on IntegriCloud