175930019STodd Fiala //===-- SBStructuredData.cpp ------------------------------------*- C++ -*-===// 275930019STodd Fiala // 375930019STodd Fiala // The LLVM Compiler Infrastructure 475930019STodd Fiala // 575930019STodd Fiala // This file is distributed under the University of Illinois Open Source 675930019STodd Fiala // License. See LICENSE.TXT for details. 775930019STodd Fiala // 875930019STodd Fiala //===----------------------------------------------------------------------===// 975930019STodd Fiala 1075930019STodd Fiala #include "lldb/API/SBStructuredData.h" 1175930019STodd Fiala 1275930019STodd Fiala #include "lldb/API/SBStream.h" 1375930019STodd Fiala #include "lldb/Core/Event.h" 14d5d8d91cSRavitheja Addepally #include "lldb/Core/StructuredDataImpl.h" 1575930019STodd Fiala #include "lldb/Target/StructuredDataPlugin.h" 1697206d57SZachary Turner #include "lldb/Utility/Status.h" 17bf9a7730SZachary Turner #include "lldb/Utility/Stream.h" 18*f2a8bccfSPavel Labath #include "lldb/Utility/StructuredData.h" 1975930019STodd Fiala 2075930019STodd Fiala using namespace lldb; 2175930019STodd Fiala using namespace lldb_private; 2275930019STodd Fiala 2375930019STodd Fiala #pragma mark-- 2475930019STodd Fiala #pragma mark SBStructuredData 2575930019STodd Fiala 262ef442c6STodd Fiala SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {} 2775930019STodd Fiala 28b9c1b51eSKate Stone SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs) 292ef442c6STodd Fiala : m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {} 3075930019STodd Fiala 31b9c1b51eSKate Stone SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp) 322ef442c6STodd Fiala : m_impl_up(new StructuredDataImpl(event_sp)) {} 3375930019STodd Fiala 34b9c1b51eSKate Stone SBStructuredData::~SBStructuredData() {} 3575930019STodd Fiala 36b9c1b51eSKate Stone SBStructuredData &SBStructuredData:: 37b9c1b51eSKate Stone operator=(const lldb::SBStructuredData &rhs) { 3875930019STodd Fiala *m_impl_up = *rhs.m_impl_up; 3975930019STodd Fiala return *this; 4075930019STodd Fiala } 4175930019STodd Fiala 42d5d8d91cSRavitheja Addepally lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) { 43d5d8d91cSRavitheja Addepally lldb::SBError error; 44d5d8d91cSRavitheja Addepally std::string json_str(stream.GetData()); 45d5d8d91cSRavitheja Addepally 46d5d8d91cSRavitheja Addepally StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str); 47d5d8d91cSRavitheja Addepally m_impl_up->SetObjectSP(json_obj); 48d5d8d91cSRavitheja Addepally 495bfee5f1SAbhishek Aggarwal if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary) 50d5d8d91cSRavitheja Addepally error.SetErrorString("Invalid Syntax"); 51d5d8d91cSRavitheja Addepally return error; 52d5d8d91cSRavitheja Addepally } 53d5d8d91cSRavitheja Addepally 54b9c1b51eSKate Stone bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); } 5575930019STodd Fiala 56b9c1b51eSKate Stone void SBStructuredData::Clear() { m_impl_up->Clear(); } 5775930019STodd Fiala 58b9c1b51eSKate Stone SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const { 59d5d8d91cSRavitheja Addepally SBError error; 60d5d8d91cSRavitheja Addepally error.SetError(m_impl_up->GetAsJSON(stream.ref())); 61d5d8d91cSRavitheja Addepally return error; 6275930019STodd Fiala } 6375930019STodd Fiala 64b9c1b51eSKate Stone lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const { 6597206d57SZachary Turner Status error = m_impl_up->GetDescription(stream.ref()); 662ef442c6STodd Fiala SBError sb_error; 672ef442c6STodd Fiala sb_error.SetError(error); 682ef442c6STodd Fiala return sb_error; 6975930019STodd Fiala } 705bfee5f1SAbhishek Aggarwal 715bfee5f1SAbhishek Aggarwal StructuredDataType SBStructuredData::GetType() const { 725bfee5f1SAbhishek Aggarwal return (m_impl_up ? m_impl_up->GetType() : eStructuredDataTypeInvalid); 735bfee5f1SAbhishek Aggarwal } 745bfee5f1SAbhishek Aggarwal 755bfee5f1SAbhishek Aggarwal size_t SBStructuredData::GetSize() const { 765bfee5f1SAbhishek Aggarwal return (m_impl_up ? m_impl_up->GetSize() : 0); 775bfee5f1SAbhishek Aggarwal } 785bfee5f1SAbhishek Aggarwal 795bfee5f1SAbhishek Aggarwal lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const { 805bfee5f1SAbhishek Aggarwal if (!m_impl_up) 815bfee5f1SAbhishek Aggarwal return SBStructuredData(); 825bfee5f1SAbhishek Aggarwal 835bfee5f1SAbhishek Aggarwal SBStructuredData result; 845bfee5f1SAbhishek Aggarwal result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key)); 855bfee5f1SAbhishek Aggarwal return result; 865bfee5f1SAbhishek Aggarwal } 875bfee5f1SAbhishek Aggarwal 885bfee5f1SAbhishek Aggarwal lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const { 895bfee5f1SAbhishek Aggarwal if (!m_impl_up) 905bfee5f1SAbhishek Aggarwal return SBStructuredData(); 915bfee5f1SAbhishek Aggarwal 925bfee5f1SAbhishek Aggarwal SBStructuredData result; 935bfee5f1SAbhishek Aggarwal result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx)); 945bfee5f1SAbhishek Aggarwal return result; 955bfee5f1SAbhishek Aggarwal } 965bfee5f1SAbhishek Aggarwal 975bfee5f1SAbhishek Aggarwal uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const { 985bfee5f1SAbhishek Aggarwal return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value); 995bfee5f1SAbhishek Aggarwal } 1005bfee5f1SAbhishek Aggarwal 1015bfee5f1SAbhishek Aggarwal double SBStructuredData::GetFloatValue(double fail_value) const { 1025bfee5f1SAbhishek Aggarwal return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value); 1035bfee5f1SAbhishek Aggarwal } 1045bfee5f1SAbhishek Aggarwal 1055bfee5f1SAbhishek Aggarwal bool SBStructuredData::GetBooleanValue(bool fail_value) const { 1065bfee5f1SAbhishek Aggarwal return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value); 1075bfee5f1SAbhishek Aggarwal } 1085bfee5f1SAbhishek Aggarwal 1095bfee5f1SAbhishek Aggarwal size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const { 1105bfee5f1SAbhishek Aggarwal return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0); 1115bfee5f1SAbhishek Aggarwal } 112