Index: include/lldb/API/LLDB.h =================================================================== --- include/lldb/API/LLDB.h +++ include/lldb/API/LLDB.h @@ -63,6 +63,8 @@ #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBThreadPlan.h" +#include "lldb/API/SBTrace.h" +#include "lldb/API/SBTraceOptions.h" #include "lldb/API/SBType.h" #include "lldb/API/SBTypeCategory.h" #include "lldb/API/SBTypeEnumMember.h" Index: include/lldb/API/SBDefines.h =================================================================== --- include/lldb/API/SBDefines.h +++ include/lldb/API/SBDefines.h @@ -79,6 +79,8 @@ class LLDB_API SBThread; class LLDB_API SBThreadCollection; class LLDB_API SBThreadPlan; +class LLDB_API SBTrace; +class LLDB_API SBTraceOptions; class LLDB_API SBType; class LLDB_API SBTypeCategory; class LLDB_API SBTypeEnumMember; Index: include/lldb/API/SBError.h =================================================================== --- include/lldb/API/SBError.h +++ include/lldb/API/SBError.h @@ -61,6 +61,7 @@ friend class SBProcess; friend class SBStructuredData; friend class SBThread; + friend class SBTrace; friend class SBTarget; friend class SBValue; friend class SBWatchpoint; Index: include/lldb/API/SBProcess.h =================================================================== --- include/lldb/API/SBProcess.h +++ include/lldb/API/SBProcess.h @@ -234,6 +234,38 @@ bool GetDescription(lldb::SBStream &description); + //------------------------------------------------------------------ + /// Start Tracing with the given SBTraceOptions. + /// + /// @param[in] options + /// Class containing TraceOptions like trace buffer size, meta + /// data buffer size, TraceType and any custom parameters + /// formatted as a JSON Array. In case of errors in formatting, + /// an error would be reported. It must be noted that tracing + /// options such as buffer sizes or other custom parameters + /// passed maybe invalid for some trace technologies. + /// In such cases the trace implementations could choose to + /// either throw an error or could round off to the nearest + /// valid options to start tracing if the passed value is not + /// supported. To obtain the actual used trace options please + /// use the GetTraceConfig API. For the custom parameters, only + /// the parameters recognized by the target would be used and + /// others would be ignored. + /// + /// @param[out] error + /// An error explaining what went wrong. + /// + /// @param[in] thread_id + /// The thread to start tracing on, use LLDB_INVALID_THREAD_ID + /// in case tracing is desired on complete process. + /// + /// @return + /// A SBTrace instance, which should be used + /// to get the trace data or other trace related operations. + //------------------------------------------------------------------ + lldb::SBTrace StartTrace(SBTraceOptions &options, lldb::SBError &error, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const; //------------------------------------------------------------------ Index: include/lldb/API/SBStream.h =================================================================== --- include/lldb/API/SBStream.h +++ include/lldb/API/SBStream.h @@ -80,6 +80,7 @@ friend class SBTarget; friend class SBThread; friend class SBThreadPlan; + friend class SBTraceOptions; friend class SBType; friend class SBTypeEnumMember; friend class SBTypeMemberFunction; Index: include/lldb/API/SBTrace.h =================================================================== --- /dev/null +++ include/lldb/API/SBTrace.h @@ -0,0 +1,125 @@ +//===-- SBTrace.h -----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SBTrace_h_ +#define LLDB_SBTrace_h_ + +#include "lldb/API/SBDefines.h" +#include "lldb/API/SBError.h" + +class SBTraceImpl; + +namespace lldb { + +class LLDB_API SBTrace { +public: + SBTrace(); + //------------------------------------------------------------------ + /// Obtain the trace data as raw bytes. + /// + /// @param[out] error + /// An error explaining what went wrong. + /// + /// @param[in] buf + /// Buffer to write the trace data to. + /// + /// @param[in] size + /// The size of the buffer used to read the data. This is + /// also the size of the data intended to read. It is also + /// possible to partially read the trace data for some trace + /// technologies by specifying a smaller buffer. + /// + /// @param[in] offset + /// The start offset to begin reading the trace data. + /// + /// @param[in] thread_id + /// Tracing could be started for the complete process or a + /// single thread, in the first case the uid obtained would + /// map to all the threads existing within the process and the + /// ones spawning later. The thread_id parameter can be used in + /// such a scenario to select the trace data for a specific + /// thread. + /// + /// @return + /// The size of the trace data effectively read by the API call. + //------------------------------------------------------------------ + size_t GetTraceData(SBError &error, void *buf, size_t size, size_t offset = 0, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + + //------------------------------------------------------------------ + /// Obtain any meta data as raw bytes for the tracing instance. + /// The input parameter definition is similar to the previous + /// function. + //------------------------------------------------------------------ + size_t GetMetaData(SBError &error, void *buf, size_t size, size_t offset = 0, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + + //------------------------------------------------------------------ + /// Stop the tracing instance. Stopping the trace will also + /// lead to deletion of any gathered trace data. + /// + /// @param[out] error + /// An error explaining what went wrong. + /// + /// @param[in] thread_id + /// The user id could map to a tracing instance for a thread + /// or could also map to a group of threads being traced with + /// the same trace options. A thread_id is normally optional + /// except in the case of tracing a complete process and tracing + /// needs to switched off on a particular thread. + /// A situation could occur where initially a thread (lets say + /// thread A) is being individually traced with a particular uid + /// and then tracing is started on the complete process, in this + /// case thread A will continue without any change. All newly + /// spawned threads would be traced with the uid of the process. + /// Now if the StopTrace API is called for the whole process, + /// thread A will not be stopped and must be stopped separately. + //------------------------------------------------------------------ + void StopTrace(SBError &error, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + + //------------------------------------------------------------------ + /// Get the trace configuration being used for the trace instance. + /// + /// @param[out] options + /// The trace options actually used by the trace instance + /// would be filled by the API. + /// + /// @param[out] error + /// An error explaining what went wrong. + /// + /// @param[in] thread_id + /// The thread_id could be optionally provided to obtain the + /// configuration used by a particular thread. + //------------------------------------------------------------------ + void GetTraceConfig(SBTraceOptions &options, SBError &error, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + + lldb::user_id_t GetTraceUID(); + + bool IsValid(); + +protected: + typedef std::shared_ptr SBTraceImplSP; + + friend class SBProcess; + + void SetTraceUID(lldb::user_id_t uid); + + SBTraceImplSP m_trace_impl_sp; + + lldb::ProcessSP GetSP() const; + + void SetSP(const ProcessSP &process_sp); + + lldb::ProcessWP m_opaque_wp; +}; +} // namespace lldb + +#endif // LLDB_SBTrace_h_ Index: include/lldb/API/SBTraceOptions.h =================================================================== --- /dev/null +++ include/lldb/API/SBTraceOptions.h @@ -0,0 +1,57 @@ +//===-- SBTraceOptions ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef SBTRACEOPTIONS_H_ +#define SBTRACEOPTIONS_H_ + +#include "lldb/API/SBDefines.h" + +namespace lldb { + +class LLDB_API SBTraceOptions { +public: + SBTraceOptions(lldb::TraceType type = lldb::TraceType::eTraceTypeNone, + uint64_t trace_buffer_size = 0, + uint64_t meta_data_buffer_size = 0); + + lldb::TraceType getType() const; + + uint64_t getTraceBufferSize() const; + + /// The trace parameters consist of any custom parameters + /// apart from the generic parameters such as + /// TraceType, trace_buffer_size and meta_data_buffer_size. + /// The returned parameters would be formatted as a JSON Array. + lldb::SBError getTraceParams(lldb::SBStream &ss); + + uint64_t getMetaDataBufferSize() const; + + /// SBStream is meant to hold any custom parameters + /// apart from meta buffer size and trace size. + /// They should be formatted as a JSON Array. + void setTraceParams(lldb::SBStream ¶ms); + + void setType(lldb::TraceType type); + + void setTraceBufferSize(uint64_t size); + + void setMetaDataBufferSize(uint64_t size); + + bool IsValid(); + +protected: + friend class SBProcess; + friend class SBTrace; + + typedef std::shared_ptr TraceOptionsSP; + TraceOptionsSP m_traceoptions_sp; +}; +} + +#endif /* SBTRACEOPTIONS_H_ */ Index: include/lldb/Target/Process.h =================================================================== --- include/lldb/Target/Process.h +++ include/lldb/Target/Process.h @@ -56,6 +56,79 @@ template struct Range; +class TraceOptions { +public: + TraceOptions(lldb::TraceType type = lldb::TraceType::eTraceTypeNone, + uint64_t trace_buffer_size = 0, + uint64_t meta_data_buffer_size = 0) + : m_type(type), m_trace_buffer_size(trace_buffer_size), + m_meta_data_buffer_size(meta_data_buffer_size), + m_trace_params(new lldb_private::StructuredData::Dictionary()) {} + + const lldb_private::StructuredData::DictionarySP &getTraceParams() const { + return m_trace_params; + } + + lldb::TraceType getType() const { return m_type; } + + uint64_t getTraceBufferSize() const { return m_trace_buffer_size; } + + uint64_t getMetaDataBufferSize() const { return m_meta_data_buffer_size; } + + void setTraceParams(std::string ¶ms) { + StructuredData::ObjectSP dict_obj = StructuredData::ParseJSON(params); + if (m_trace_params && dict_obj && dict_obj->GetAsDictionary() != nullptr) { + StructuredData::Dictionary *dict_ptr = dict_obj->GetAsDictionary(); + dict_ptr->ForEach( + [this](ConstString key, StructuredData::Object *object) -> bool { + if (object == nullptr) + return true; + switch (object->GetType()) { + case StructuredData::Type::eTypeFloat: + m_trace_params->AddFloatItem(key.GetStringRef(), + object->GetFloatValue()); + break; + case StructuredData::Type::eTypeInteger: + m_trace_params->AddIntegerItem(key.GetStringRef(), + object->GetIntegerValue()); + break; + case StructuredData::Type::eTypeString: + m_trace_params->AddStringItem(key.GetStringRef(), + object->GetStringValue()); + break; + case StructuredData::Type::eTypeBoolean: + m_trace_params->AddBooleanItem(key.GetStringRef(), + object->GetBooleanValue()); + break; + default: + break; + } + return true; + }); + } + } + + void setType(lldb::TraceType type) { m_type = type; } + + void setTraceBufferSize(uint64_t size) { m_trace_buffer_size = size; } + + void setMetaDataBufferSize(uint64_t size) { m_meta_data_buffer_size = size; } + +private: + lldb::TraceType m_type; + uint64_t m_trace_buffer_size; + uint64_t m_meta_data_buffer_size; + + /// m_trace_params is meant to hold any custom parameters + /// apart from meta buffer size and trace size. + /// They should be formatted as Name:Value; pairs. + /// Where the Value should be a 64 bit unsigned hexadecimal + /// integer. + /// The interpretation of such parameters is left to + /// the lldb-server. + lldb_private::StructuredData::DictionarySP m_trace_params; +}; + //---------------------------------------------------------------------- // ProcessProperties //---------------------------------------------------------------------- @@ -2764,6 +2837,78 @@ lldb::StructuredDataPluginSP GetStructuredDataPlugin(const ConstString &type_name) const; + //------------------------------------------------------------------ + /// Starts tracing with the configuration provided in options on + /// thread_id. To enable tracing on the complete process the + /// thread_id should be set to LLDB_INVALID_THREAD_ID. + /// The API returns a user_id which is needed by other API's + /// that manipulate the trace instance. + /// The handling of erroneous or unsupported configuration is left + /// to the trace technology implementations in the server, as they + /// could be returned as an error, or rounded to a valid + /// configuration to start tracing. In the later case the + /// GetTraceConfig should supply the actual used trace + /// configuration. + //------------------------------------------------------------------ + virtual lldb::user_id_t StartTrace(lldb::TraceOptionsSP &options, + lldb::tid_t thread_id, Error &error) { + error.SetErrorString("Not implemented"); + return LLDB_INVALID_UID; + } + + //------------------------------------------------------------------ + /// Stops the tracing instance leading to deletion of the trace + /// data. The tracing instance is identified by the user_id which + /// is obtained when tracing was started from the StartTrace. + /// In case tracing of the complete process needs to be stopped + /// the thread_id should be set to LLDB_INVALID_THREAD_ID. + /// In the other case that tracing on an individual thread needs + /// to be stopped a thread_id can be supplied. + //------------------------------------------------------------------ + virtual void StopTrace(lldb::user_id_t uid, lldb::tid_t thread_id, + Error &error) { + error.SetErrorString("Not implemented"); + } + + //------------------------------------------------------------------ + /// Provides the trace data as raw bytes. A buffer needs to be + /// supplied to copy the trace data. The exact behavior of this API + /// may vary across trace technology, as some may support partial + /// reading of the trace data from a specified offset while some + /// may not. The thread_id shoould be used to select a particular + /// thread for trace extraction. + //------------------------------------------------------------------ + virtual size_t GetData(lldb::user_id_t uid, lldb::tid_t thread_id, + Error &error, void *buf, size_t size, + size_t offset = 0) { + error.SetErrorString("Not implemented"); + return 0; + } + + //------------------------------------------------------------------ + /// Similar API as above except for obtaining meta data + //------------------------------------------------------------------ + virtual size_t GetMetaData(lldb::user_id_t uid, lldb::tid_t thread_id, + Error &error, void *buf, size_t size, + size_t offset = 0) { + error.SetErrorString("Not implemented"); + return 0; + } + + //------------------------------------------------------------------ + /// API to obtain the trace configuration used by a trace instance. + /// Configurations that may be specific to some trace technology + /// should be stored as a Name:Value; pair in the string. The + /// options are transported to the server, which shall interpret + /// accordingly. The thread_id should also match the uid otherwise + /// an error will be returned. + //------------------------------------------------------------------ + virtual void GetTraceConfig(lldb::user_id_t uid, lldb::tid_t thread_id, + Error &error, lldb::TraceOptionsSP &options) { + error.SetErrorString("Not implemented"); + return; + } + protected: void SetState(lldb::EventSP &event_sp); Index: include/lldb/lldb-enumerations.h =================================================================== --- include/lldb/lldb-enumerations.h +++ include/lldb/lldb-enumerations.h @@ -718,6 +718,8 @@ eBasicTypeOther }; +enum TraceType { eTraceTypeNone = 0, eTraceTypeProcessorTrace }; + FLAGS_ENUM(TypeClass){ eTypeClassInvalid = (0u), eTypeClassArray = (1u << 0), eTypeClassBlockPointer = (1u << 1), eTypeClassBuiltin = (1u << 2), Index: include/lldb/lldb-forward.h =================================================================== --- include/lldb/lldb-forward.h +++ include/lldb/lldb-forward.h @@ -255,6 +255,7 @@ class ThreadPlanStepThrough; class ThreadPlanTracer; class ThreadSpec; +class TraceOptions; class Type; class TypeAndOrName; class TypeCategoryMap; @@ -453,6 +454,7 @@ typedef std::shared_ptr ThreadCollectionSP; typedef std::shared_ptr ThreadPlanSP; typedef std::shared_ptr ThreadPlanTracerSP; +typedef std::shared_ptr TraceOptionsSP; typedef std::shared_ptr TypeSP; typedef std::weak_ptr TypeWP; typedef std::shared_ptr TypeCategoryImplSP; Index: scripts/interface/SBProcess.i =================================================================== --- scripts/interface/SBProcess.i +++ scripts/interface/SBProcess.i @@ -408,6 +408,10 @@ lldb::SBError SaveCore(const char *file_name); + lldb::SBTrace + StartTrace(SBTraceOptions &options, lldb::SBError &error, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr, lldb::SBMemoryRegionInfo ®ion_info); Index: scripts/interface/SBTrace.i =================================================================== --- /dev/null +++ scripts/interface/SBTrace.i @@ -0,0 +1,35 @@ +//===-- SWIG Interface for SBTrace.h ----------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +namespace lldb { + +class LLDB_API SBTrace { +public: + SBTrace(); + size_t GetTraceData(SBError &error, void *buf, + size_t size, size_t offset, + lldb::tid_t thread_id); + + size_t GetMetaData(SBError &error, void *buf, + size_t size, size_t offset, + lldb::tid_t thread_id); + + void StopTrace(SBError &error, + lldb::tid_t thread_id); + + void GetTraceConfig(SBTraceOptions &options, + SBError &error, + lldb::tid_t thread_id); + + lldb::user_id_t GetTraceUID(); + + bool IsValid(); + +}; +} // namespace lldb \ No newline at end of file Index: scripts/interface/SBTraceOptions.i =================================================================== --- /dev/null +++ scripts/interface/SBTraceOptions.i @@ -0,0 +1,36 @@ +//===-- SWIG Interface for SBTraceOptions -----------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +namespace lldb { + +class LLDB_API SBTraceOptions { +public: + SBTraceOptions(lldb::TraceType type = lldb::TraceType::eTraceTypeNone, + uint64_t trace_buffer_size = 0, + uint64_t meta_data_buffer_size = 0); + + lldb::TraceType getType() const; + + uint64_t getTraceBufferSize() const; + + lldb::SBError getTraceParams(lldb::SBStream &ss); + + uint64_t getMetaDataBufferSize() const; + + void setTraceParams(lldb::SBStream ¶ms); + + void setType(lldb::TraceType type); + + void setTraceBufferSize(uint64_t size); + + void setMetaDataBufferSize(uint64_t size); + + bool IsValid(); +}; +} Index: scripts/lldb.swig =================================================================== --- scripts/lldb.swig +++ scripts/lldb.swig @@ -103,6 +103,8 @@ #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBThreadPlan.h" +#include "lldb/API/SBTrace.h" +#include "lldb/API/SBTraceOptions.h" #include "lldb/API/SBType.h" #include "lldb/API/SBTypeCategory.h" #include "lldb/API/SBTypeEnumMember.h" @@ -186,6 +188,8 @@ %include "./interface/SBThread.i" %include "./interface/SBThreadCollection.i" %include "./interface/SBThreadPlan.i" +%include "./interface/SBTrace.i" +%include "./interface/SBTraceOptions.i" %include "./interface/SBType.i" %include "./interface/SBTypeCategory.i" %include "./interface/SBTypeEnumMember.i" Index: source/API/CMakeLists.txt =================================================================== --- source/API/CMakeLists.txt +++ source/API/CMakeLists.txt @@ -65,6 +65,8 @@ SBThread.cpp SBThreadCollection.cpp SBThreadPlan.cpp + SBTrace.cpp + SBTraceOptions.cpp SBType.cpp SBTypeCategory.cpp SBTypeEnumMember.cpp Index: source/API/SBProcess.cpp =================================================================== --- source/API/SBProcess.cpp +++ source/API/SBProcess.cpp @@ -44,6 +44,8 @@ #include "lldb/API/SBStructuredData.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" +#include "lldb/API/SBTrace.h" +#include "lldb/API/SBTraceOptions.h" #include "lldb/API/SBUnixSignals.h" using namespace lldb; @@ -349,6 +351,35 @@ return bytes_read; } +lldb::SBTrace SBProcess::StartTrace(SBTraceOptions &options, + lldb::SBError &error, + lldb::tid_t thread_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + error.Clear(); + SBTrace trace_instance; + trace_instance.SetSP(process_sp); + lldb::user_id_t uid = LLDB_INVALID_UID; + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + error.SetErrorString("invalid process"); + } else { + + if (log) + log->Printf("SBProcess:: %s ", __FUNCTION__); + + uid = process_sp->StartTrace(options.m_traceoptions_sp, thread_id, + error.ref()); + trace_instance.SetTraceUID(uid); + if (log) + log->Printf("SBProcess:: %s returned uid - %" PRIx64, __FUNCTION__, uid); + } + return trace_instance; +} + void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const { if (out == NULL) return; Index: source/API/SBTrace.cpp =================================================================== --- /dev/null +++ source/API/SBTrace.cpp @@ -0,0 +1,128 @@ +//===-- SBTrace.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/Core/Log.h" +#include "lldb/Target/Process.h" + +#include "lldb/API/SBTrace.h" +#include "lldb/API/SBTraceOptions.h" + +using namespace lldb; +using namespace lldb_private; + +class SBTraceImpl { +public: + lldb::user_id_t uid; +}; + +lldb::ProcessSP SBTrace::GetSP() const { return m_opaque_wp.lock(); } + +size_t SBTrace::GetTraceData(SBError &error, void *buf, size_t size, + size_t offset, lldb::tid_t thread_id) { + size_t bytes_read = 0; + ProcessSP process_sp(GetSP()); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + error.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + error.SetErrorString("invalid process"); + } else { + bytes_read = process_sp->GetData(GetTraceUID(), thread_id, error.ref(), buf, + size, offset); + if (log) + log->Printf("SBProcess:: %s bytes_read - %" PRIx64, __FUNCTION__, + bytes_read); + } + return bytes_read; +} + +size_t SBTrace::GetMetaData(SBError &error, void *buf, size_t size, + size_t offset, lldb::tid_t thread_id) { + size_t bytes_read = 0; + ProcessSP process_sp(GetSP()); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + error.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + error.SetErrorString("invalid process"); + } else { + + bytes_read = process_sp->GetMetaData(GetTraceUID(), thread_id, error.ref(), + buf, size, offset); + if (log) + log->Printf("SBProcess:: %s bytes_read - %" PRIx64, __FUNCTION__, + bytes_read); + } + return bytes_read; +} + +void SBTrace::StopTrace(SBError &error, lldb::tid_t thread_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + error.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + error.SetErrorString("invalid process"); + return; + } + process_sp->StopTrace(GetTraceUID(), thread_id, error.ref()); +} + +void SBTrace::GetTraceConfig(SBTraceOptions &options, SBError &error, + lldb::tid_t thread_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + error.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + error.SetErrorString("invalid process"); + } else { + process_sp->GetTraceConfig(GetTraceUID(), thread_id, error.ref(), + options.m_traceoptions_sp); + } +} + +lldb::user_id_t SBTrace::GetTraceUID() { + if (m_trace_impl_sp) + return m_trace_impl_sp->uid; + return LLDB_INVALID_UID; +} + +void SBTrace::SetTraceUID(lldb::user_id_t uid) { + if (m_trace_impl_sp) + m_trace_impl_sp->uid = uid; +} + +SBTrace::SBTrace() { + m_trace_impl_sp.reset(new SBTraceImpl); + if (m_trace_impl_sp) + m_trace_impl_sp->uid = LLDB_INVALID_UID; +} + +void SBTrace::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; } + +bool SBTrace::IsValid() { + if (!m_trace_impl_sp) + return false; + if (!GetSP()) + return false; + return true; +} Index: source/API/SBTraceOptions.cpp =================================================================== --- /dev/null +++ source/API/SBTraceOptions.cpp @@ -0,0 +1,83 @@ +//===-- SBTraceOptions.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/SBTraceOptions.h" +#include "lldb/API/SBError.h" +#include "lldb/API/SBStream.h" +#include "lldb/Core/Log.h" +#include "lldb/Target/Process.h" + +using namespace lldb; +using namespace lldb_private; + +SBTraceOptions::SBTraceOptions(lldb::TraceType type, uint64_t trace_buffer_size, + uint64_t meta_data_buffer_size) { + m_traceoptions_sp.reset( + new TraceOptions(type, trace_buffer_size, meta_data_buffer_size)); +} + +lldb::TraceType SBTraceOptions::getType() const { + if (m_traceoptions_sp) + return m_traceoptions_sp->getType(); + return lldb::TraceType::eTraceTypeNone; +} + +uint64_t SBTraceOptions::getTraceBufferSize() const { + if (m_traceoptions_sp) + return m_traceoptions_sp->getTraceBufferSize(); + return 0; +} + +lldb::SBError SBTraceOptions::getTraceParams(lldb::SBStream &ss) { + const lldb_private::StructuredData::DictionarySP dict_obj = + m_traceoptions_sp->getTraceParams(); + lldb::SBError error; + if (dict_obj) { + dict_obj->Dump(ss.ref(), false); + } else + error.SetErrorString("Empty trace params"); + return error; +} + +uint64_t SBTraceOptions::getMetaDataBufferSize() const { + if (m_traceoptions_sp) + return m_traceoptions_sp->getTraceBufferSize(); + return 0; +} + +void SBTraceOptions::setTraceParams(lldb::SBStream ¶ms) { + if (params.GetData() == NULL) + return; + if (m_traceoptions_sp) { + std::string str(params.GetData()); + m_traceoptions_sp->setTraceParams(str); + return; + } +} + +void SBTraceOptions::setType(lldb::TraceType type) { + if (m_traceoptions_sp) + m_traceoptions_sp->setType(type); +} + +void SBTraceOptions::setTraceBufferSize(uint64_t size) { + if (m_traceoptions_sp) + m_traceoptions_sp->setTraceBufferSize(size); +} + +void SBTraceOptions::setMetaDataBufferSize(uint64_t size) { + if (m_traceoptions_sp) + m_traceoptions_sp->setMetaDataBufferSize(size); +} + +bool SBTraceOptions::IsValid() { + if (m_traceoptions_sp) + return true; + return false; +}