From e14dc26857470f248e5fc1dd14d89314eae47fa5 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Mon, 12 Sep 2016 23:10:56 +0000 Subject: 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. llvm-svn: 281273 --- lldb/source/Core/StructuredData.cpp | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'lldb/source/Core/StructuredData.cpp') 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 #include +#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 -- cgit v1.2.3