2016-08-19 12:21:48 +08:00
|
|
|
//===-- SBStructuredData.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBStructuredData.h"
|
|
|
|
|
|
|
|
#include "lldb/API/SBStream.h"
|
2018-09-14 05:35:32 +08:00
|
|
|
#include "lldb/API/SBStringList.h"
|
2017-04-26 16:48:50 +08:00
|
|
|
#include "lldb/Core/StructuredDataImpl.h"
|
2016-08-19 12:21:48 +08:00
|
|
|
#include "lldb/Target/StructuredDataPlugin.h"
|
2018-12-14 23:59:49 +08:00
|
|
|
#include "lldb/Utility/Event.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-06-27 18:45:31 +08:00
|
|
|
#include "lldb/Utility/StructuredData.h"
|
2016-08-19 12:21:48 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
#pragma mark--
|
2016-08-19 12:21:48 +08:00
|
|
|
#pragma mark SBStructuredData
|
|
|
|
|
2016-11-10 07:21:04 +08:00
|
|
|
SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBStructuredData::SBStructuredData(const lldb::SBStructuredData &rhs)
|
2016-11-10 07:21:04 +08:00
|
|
|
: m_impl_up(new StructuredDataImpl(*rhs.m_impl_up.get())) {}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBStructuredData::SBStructuredData(const lldb::EventSP &event_sp)
|
2016-11-10 07:21:04 +08:00
|
|
|
: m_impl_up(new StructuredDataImpl(event_sp)) {}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
SBStructuredData::SBStructuredData(lldb_private::StructuredDataImpl *impl)
|
|
|
|
: m_impl_up(impl) {}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBStructuredData::~SBStructuredData() {}
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBStructuredData &SBStructuredData::
|
|
|
|
operator=(const lldb::SBStructuredData &rhs) {
|
|
|
|
*m_impl_up = *rhs.m_impl_up;
|
|
|
|
return *this;
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
|
|
|
|
2017-04-26 16:48:50 +08:00
|
|
|
lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
|
|
|
|
lldb::SBError error;
|
|
|
|
std::string json_str(stream.GetData());
|
|
|
|
|
|
|
|
StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str);
|
|
|
|
m_impl_up->SetObjectSP(json_obj);
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)
|
2017-04-26 16:48:50 +08:00
|
|
|
error.SetErrorString("Invalid Syntax");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); }
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBStructuredData::Clear() { m_impl_up->Clear(); }
|
2016-08-19 12:21:48 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const {
|
2017-04-26 16:48:50 +08:00
|
|
|
SBError error;
|
|
|
|
error.SetError(m_impl_up->GetAsJSON(stream.ref()));
|
|
|
|
return error;
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error = m_impl_up->GetDescription(stream.ref());
|
2016-11-10 07:21:04 +08:00
|
|
|
SBError sb_error;
|
|
|
|
sb_error.SetError(error);
|
|
|
|
return sb_error;
|
2016-08-19 12:21:48 +08:00
|
|
|
}
|
2017-05-29 16:25:46 +08:00
|
|
|
|
|
|
|
StructuredDataType SBStructuredData::GetType() const {
|
|
|
|
return (m_impl_up ? m_impl_up->GetType() : eStructuredDataTypeInvalid);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetSize() const {
|
|
|
|
return (m_impl_up ? m_impl_up->GetSize() : 0);
|
|
|
|
}
|
|
|
|
|
2018-09-14 05:35:32 +08:00
|
|
|
bool SBStructuredData::GetKeys(lldb::SBStringList &keys) const {
|
|
|
|
if (!m_impl_up)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (GetType() != eStructuredDataTypeDictionary)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
StructuredData::ObjectSP obj_sp = m_impl_up->GetObjectSP();
|
|
|
|
if (!obj_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
StructuredData::Dictionary *dict = obj_sp->GetAsDictionary();
|
|
|
|
// We claimed we were a dictionary, so this can't be null.
|
|
|
|
assert(dict);
|
|
|
|
// The return kind of GetKeys is an Array:
|
|
|
|
StructuredData::ObjectSP array_sp = dict->GetKeys();
|
|
|
|
StructuredData::Array *key_arr = array_sp->GetAsArray();
|
|
|
|
assert(key_arr);
|
|
|
|
|
|
|
|
key_arr->ForEach([&keys] (StructuredData::Object *object) -> bool {
|
|
|
|
llvm::StringRef key = object->GetStringValue("");
|
|
|
|
keys.AppendString(key.str().c_str());
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-29 16:25:46 +08:00
|
|
|
lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const {
|
|
|
|
if (!m_impl_up)
|
|
|
|
return SBStructuredData();
|
|
|
|
|
|
|
|
SBStructuredData result;
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const {
|
|
|
|
if (!m_impl_up)
|
|
|
|
return SBStructuredData();
|
|
|
|
|
|
|
|
SBStructuredData result;
|
|
|
|
result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const {
|
|
|
|
return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
double SBStructuredData::GetFloatValue(double fail_value) const {
|
|
|
|
return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBStructuredData::GetBooleanValue(bool fail_value) const {
|
|
|
|
return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const {
|
|
|
|
return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0);
|
|
|
|
}
|