diff options
author | Ravitheja Addepally <ravitheja.addepally@intel.com> | 2017-04-26 08:48:50 +0000 |
---|---|---|
committer | Ravitheja Addepally <ravitheja.addepally@intel.com> | 2017-04-26 08:48:50 +0000 |
commit | d5d8d91c1db18b984adb43632a1832202a0ecf1b (patch) | |
tree | 7391e1acfc7b953e755552c21ed20778ade191f1 /lldb/source/API/SBStructuredData.cpp | |
parent | 2bcd94f8d8959a523adf8211c57a94782d561ca5 (diff) | |
download | bcm5719-llvm-d5d8d91c1db18b984adb43632a1832202a0ecf1b.tar.gz bcm5719-llvm-d5d8d91c1db18b984adb43632a1832202a0ecf1b.zip |
Initial implementation of SB APIs for Tracing support.
Summary:
This patch introduces new SB APIs for tracing support
inside LLDB. The idea is to gather trace data from
LLDB and provide it through this APIs to external
tools integrating with LLDB. These tools will be
responsible for interpreting and presenting the
trace data to their users.
The patch implements the following new SB APIs ->
-> StartTrace - starts tracing with given parameters
-> StopTrace - stops tracing.
-> GetTraceData - read the trace data .
-> GetMetaData - read the meta data assosciated with the trace.
-> GetTraceConfig - read the trace configuration
Tracing is associated with a user_id that is returned
by the StartTrace API and this id needs to be used
for accessing the trace data and also Stopping
the trace. The user_id itself may map to tracing
the complete process or just an individual thread.
The APIs require an additional thread parameter
when the user of these APIs wishes to perform
thread specific manipulations on the tracing instances.
The patch also includes the corresponding
python wrappers for the C++ based APIs.
Reviewers: k8stone, lldb-commits, clayborg
Reviewed By: clayborg
Subscribers: jingham, mgorny
Differential Revision: https://reviews.llvm.org/D29581
llvm-svn: 301389
Diffstat (limited to 'lldb/source/API/SBStructuredData.cpp')
-rw-r--r-- | lldb/source/API/SBStructuredData.cpp | 81 |
1 files changed, 16 insertions, 65 deletions
diff --git a/lldb/source/API/SBStructuredData.cpp b/lldb/source/API/SBStructuredData.cpp index 6d4c862306f..2fca56f2f22 100644 --- a/lldb/source/API/SBStructuredData.cpp +++ b/lldb/source/API/SBStructuredData.cpp @@ -12,6 +12,7 @@ #include "lldb/API/SBStream.h" #include "lldb/Core/Event.h" #include "lldb/Core/StructuredData.h" +#include "lldb/Core/StructuredDataImpl.h" #include "lldb/Target/StructuredDataPlugin.h" #include "lldb/Utility/Error.h" #include "lldb/Utility/Stream.h" @@ -20,70 +21,6 @@ using namespace lldb; using namespace lldb_private; #pragma mark-- -#pragma mark StructuredDataImpl - -class StructuredDataImpl { -public: - StructuredDataImpl() : m_plugin_wp(), m_data_sp() {} - - StructuredDataImpl(const StructuredDataImpl &rhs) = default; - - StructuredDataImpl(const EventSP &event_sp) - : m_plugin_wp( - EventDataStructuredData::GetPluginFromEvent(event_sp.get())), - m_data_sp(EventDataStructuredData::GetObjectFromEvent(event_sp.get())) { - } - - ~StructuredDataImpl() = default; - - StructuredDataImpl &operator=(const StructuredDataImpl &rhs) = default; - - bool IsValid() const { return m_data_sp.get() != nullptr; } - - void Clear() { - m_plugin_wp.reset(); - m_data_sp.reset(); - } - - SBError GetAsJSON(lldb_private::Stream &stream) const { - SBError sb_error; - - if (!m_data_sp) { - sb_error.SetErrorString("No structured data."); - return sb_error; - } - - m_data_sp->Dump(stream); - return sb_error; - } - - Error GetDescription(lldb_private::Stream &stream) const { - Error error; - - if (!m_data_sp) { - error.SetErrorString("Cannot pretty print structured data: " - "no data to print."); - return error; - } - - // Grab the plugin. - auto plugin_sp = StructuredDataPluginSP(m_plugin_wp); - if (!plugin_sp) { - error.SetErrorString("Cannot pretty print structured data: " - "plugin doesn't exist."); - return error; - } - - // Get the data's description. - return plugin_sp->GetDescription(m_data_sp, stream); - } - -private: - StructuredDataPluginWP m_plugin_wp; - StructuredData::ObjectSP m_data_sp; -}; - -#pragma mark-- #pragma mark SBStructuredData SBStructuredData::SBStructuredData() : m_impl_up(new StructuredDataImpl()) {} @@ -102,12 +39,26 @@ operator=(const lldb::SBStructuredData &rhs) { return *this; } +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); + + if (!json_obj || json_obj->GetType() != StructuredData::Type::eTypeDictionary) + error.SetErrorString("Invalid Syntax"); + return error; +} + bool SBStructuredData::IsValid() const { return m_impl_up->IsValid(); } void SBStructuredData::Clear() { m_impl_up->Clear(); } SBError SBStructuredData::GetAsJSON(lldb::SBStream &stream) const { - return m_impl_up->GetAsJSON(stream.ref()); + SBError error; + error.SetError(m_impl_up->GetAsJSON(stream.ref())); + return error; } lldb::SBError SBStructuredData::GetDescription(lldb::SBStream &stream) const { |