blob: 2fca56f2f2231bc000bf3a84f658d70a92760b9f [file] [log] [blame]
Todd Fiala75930012016-08-19 04:21:48 +00001//===-- SBStructuredData.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBStructuredData.h"
11
12#include "lldb/API/SBStream.h"
Todd Fiala75930012016-08-19 04:21:48 +000013#include "lldb/Core/Event.h"
Todd Fiala75930012016-08-19 04:21:48 +000014#include "lldb/Core/StructuredData.h"
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000015#include "lldb/Core/StructuredDataImpl.h"
Todd Fiala75930012016-08-19 04:21:48 +000016#include "lldb/Target/StructuredDataPlugin.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000017#include "lldb/Utility/Error.h"
18#include "lldb/Utility/Stream.h"
Todd Fiala75930012016-08-19 04:21:48 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023#pragma mark--
Todd Fiala75930012016-08-19 04:21:48 +000024#pragma mark SBStructuredData
25
Todd Fiala2ef442c2016-11-09 23:21:04 +000026SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {}
Todd Fiala75930012016-08-19 04:21:48 +000027
Kate Stoneb9c1b512016-09-06 20:57:50 +000028SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
Todd Fiala2ef442c2016-11-09 23:21:04 +000029 : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {}
Kate Stoneb9c1b512016-09-06 20:57:50 +000030
31SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
Todd Fiala2ef442c2016-11-09 23:21:04 +000032 : m_impl_up(new StructuredDataImpl(event_sp)) {}
Kate Stoneb9c1b512016-09-06 20:57:50 +000033
34SBStructuredData::~SBStructuredData() {}
35
36SBStructuredData &SBStructuredData::
37operator=(const lldb::SBStructuredData &rhs) {
38 *m_impl_up = *rhs.m_impl_up;
39 return *this;
Todd Fiala75930012016-08-19 04:21:48 +000040}
41
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000042lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
43 lldb::SBError error;
44 std::string json_str(stream.GetData());
45
46 StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str);
47 m_impl_up->SetObjectSP(json_obj);
48
49 if (!json_obj || json_obj->GetType() != StructuredData::Type::eTypeDictionary)
50 error.SetErrorString("Invalid Syntax");
51 return error;
52}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); }
55
56void SBStructuredData::Clear() { m_impl_up->Clear(); }
57
58SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +000059 SBError error;
60 error.SetError(m_impl_up->GetAsJSON(stream.ref()));
61 return error;
Todd Fiala75930012016-08-19 04:21:48 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
Todd Fiala2ef442c2016-11-09 23:21:04 +000065 Error error = m_impl_up->GetDescription(stream.ref());
66 SBError sb_error;
67 sb_error.SetError(error);
68 return sb_error;
Todd Fiala75930012016-08-19 04:21:48 +000069}