Index: include/lldb/API/LLDB.h =================================================================== --- include/lldb/API/LLDB.h +++ include/lldb/API/LLDB.h @@ -63,6 +63,7 @@ #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBThreadPlan.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,7 @@ class LLDB_API SBThread; class LLDB_API SBThreadCollection; class LLDB_API SBThreadPlan; +class LLDB_API SBTraceOptions; class LLDB_API SBType; class LLDB_API SBTypeCategory; class LLDB_API SBTypeEnumMember; Index: include/lldb/API/SBProcess.h =================================================================== --- include/lldb/API/SBProcess.h +++ include/lldb/API/SBProcess.h @@ -234,6 +234,136 @@ bool GetDescription(lldb::SBStream &description); + //------------------------------------------------------------------ + /// Start Tracing with the given SBTraceOptions. + /// + /// @param[in] sboptions + /// Class containing TraceOptions like trace buffer size, meta + /// data buffer size, TraceType and a SBStream (contains custom + /// parameters formatted as a list of "Name:Value;" pairs where + /// the Value should be a 64 bit unsigned hex integer). 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 Name:Value pairs recognized by the target would be + /// used and others would be ignored. + /// + /// @param[out] sberror + /// 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 user id for the trace instance, which should be used + /// to get the trace data or other trace related operations. + //------------------------------------------------------------------ + lldb::user_id_t StartTrace(SBTraceOptions &sboptions, lldb::SBError &sberror, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + + //------------------------------------------------------------------ + /// Obtain the trace data as raw bytes. + /// + /// @param[in] uid + /// The user id obtained from the corresponding StartTrace of + /// the tracing instance. + /// + /// @param[out] sberror + /// 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(lldb::user_id_t uid, SBError &sberror, 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(lldb::user_id_t uid, SBError &sberror, 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[in] uid + /// The user id obtained from the corresponding StartTrace of + /// the tracing instance. + /// + /// @param[out] sberror + /// 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(lldb::user_id_t uid, SBError &sberror, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + + //------------------------------------------------------------------ + /// Get the trace configuration being used for the trace instance. + /// + /// @param[out] sboptions + /// The trace options actually used by the trace instance + /// would be filled by the API. + /// + /// @param[in] uid + /// The user id obtained from the corresponding StartTrace of + /// the tracing instance. + /// + /// @param[out] sberror + /// 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 &sboptions, lldb::user_id_t uid, + SBError &sberror, + lldb::tid_t thread_id = LLDB_INVALID_THREAD_ID); + uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const; //------------------------------------------------------------------ Index: include/lldb/API/SBTraceOptions.h =================================================================== --- /dev/null +++ include/lldb/API/SBTraceOptions.h @@ -0,0 +1,68 @@ +//===-- 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" +#include "lldb/API/SBStream.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) + : m_type(type), m_trace_params(), m_trace_buffer_size(trace_buffer_size), + m_meta_data_buffer_size(meta_data_buffer_size) {} + + lldb::TraceType getType() const { return m_type; } + + uint64_t getTraceBufferSize() const { return m_trace_buffer_size; } + + /// The trace params 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 Name:Value; + /// pairs, where the value would be formatted as a 64-bit hex + /// integer. + const char *getTraceParams() { return m_trace_params.GetData(); } + + uint64_t getMetaDataBufferSize() const { return m_meta_data_buffer_size; } + + /// SBStream is meant to hold any custom parameters + /// apart from meta buffer size and trace size. + /// They should be formatted as Name:Value; pairs. + /// The Value should be 64-bit(unsigned) hex encoded + /// integer. + void setTraceParams(SBStream ¶ms) { + m_trace_params.Clear(); + if (params.GetData() == NULL) + return; + m_trace_params.Printf("%s", params.GetData()); + } + + 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; + + SBStream m_trace_params; + uint64_t m_trace_buffer_size; + uint64_t m_meta_data_buffer_size; +}; +} + +#endif /* SBTRACEOPTIONS_H_ */ Index: include/lldb/Host/common/NativeProcessProtocol.h =================================================================== --- include/lldb/Host/common/NativeProcessProtocol.h +++ include/lldb/Host/common/NativeProcessProtocol.h @@ -288,6 +288,177 @@ static Error Attach(lldb::pid_t pid, NativeDelegate &native_delegate, MainLoop &mainloop, NativeProcessProtocolSP &process_sp); + //------------------------------------------------------------------ + /// TraceOptions class to store the parameters for different + /// TraceTypes. Parameters that don't fit into the class members + /// should be stored in the trace params map as Name:Value pairs. + /// + /// Tracing technologies wanting to integrate into lldb can + /// use this class in conjunction with the other tracing API's. + //------------------------------------------------------------------ + class TraceOptions { + public: + TraceOptions(lldb::TraceType type = lldb::TraceType::eTraceTypeNone) + : m_type(type), m_trace_buffer_size(0), m_meta_data_buffer_size(0) {} + + void clear() { + m_type = lldb::TraceType::eTraceTypeNone; + m_trace_buffer_size = m_meta_data_buffer_size = 0; + m_trace_params.clear(); + } + + 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; } + + const std::map &getTraceParams() const { + return m_trace_params; + } + + 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; + } + + void setTraceParam(const std::string &key, uint64_t value) { + m_trace_params[key] = value; + } + + private: + lldb::TraceType m_type; + + std::map m_trace_params; + uint64_t m_trace_buffer_size; + uint64_t m_meta_data_buffer_size; + }; + + //------------------------------------------------------------------ + /// StartTracing API for starting a tracing instance with the + /// TraceOptions on a specific thread. + /// + /// @param[in] thread + /// The thread to start tracing on, in case whole process needs + /// to be traced use INVALID_THREAD_ID. + /// + /// @param[in] config + /// The configuration to use when starting tracing. + /// + /// @param[out] error + /// Error indicates what went wrong. + /// + /// @return + /// The API returns a user_id which can be used to get trace + /// data, trace configuration or stopping the trace instance. + /// The user_id is a key to identify and operate with a tracing + /// instance. It may refer to the complete process or a single + /// thread. + //------------------------------------------------------------------ + virtual lldb::user_id_t StartTracing(lldb::tid_t thread, TraceOptions &config, + Error &error) { + error.SetErrorString("Not implemented"); + return LLDB_INVALID_UID; + } + + //------------------------------------------------------------------ + /// Similar API as above except used to enable tracing on complete + /// process. Once tracing is enabled for the whole process, all + /// newly spawned threads will also be traced with the same config + /// but any errors occurring for starting the trace for them will + /// not be reported as those would be through async notifications. + //------------------------------------------------------------------ + virtual lldb::user_id_t StartTracingAllThreads(TraceOptions &config, + Error &error) { + error.SetErrorString("Not implemented"); + return LLDB_INVALID_UID; + } + + //------------------------------------------------------------------ + /// StopTracing API as the name suggests stops a tracing instance. + /// + /// @param[in] uid + /// The user id of the trace intended to be stopped. Now a + /// user_id may map to multiple threads in which case this API + /// could be used to stop the tracing for a specific thread by + /// supplying its thread id. + /// + /// @param[in] thread + /// Thread is needed when the complete process is being traced + /// and the user wishes to stop tracing on a particular thread. + /// + /// @return + /// Error indicating what went wrong. + //------------------------------------------------------------------ + virtual Error StopTracing(lldb::user_id_t uid, + lldb::tid_t thread = LLDB_INVALID_THREAD_ID) { + Error error; + error.SetErrorString("Not implemented"); + return error; + } + + //------------------------------------------------------------------ + /// This API provides the trace data collected in the form of raw + /// data. + /// + /// @param[in] uid thread + /// The uid and thread provide the context for the trace + /// instance. + /// + /// @param[in] buf buf_size + /// The buf and buf_size provide the destination buffer + /// where the trace data would be read to. + /// + /// @param[in] offset + /// There is possibility to read partially the trace data from + /// a specified offset where in such cases the buffer provided + /// may be smaller than the internal trace collection container. + /// + /// @return + /// The size of the data actually read. + //------------------------------------------------------------------ + virtual size_t GetTraceData(lldb::user_id_t uid, lldb::tid_t thread, + Error &error, void *buf, size_t buf_size, + size_t offset = 0) { + error.SetErrorString("Not implemented"); + return 0; + } + + //------------------------------------------------------------------ + /// Similar API as above except it aims to provide any extra data + /// useful for decoding the actual trace data. + //------------------------------------------------------------------ + virtual size_t GetTraceMetaData(lldb::user_id_t uid, lldb::tid_t thread, + Error &error, void *buf, size_t buf_size, + size_t offset = 0) { + error.SetErrorString("Not implemented"); + return 0; + } + + //------------------------------------------------------------------ + /// API to query the TraceOptions for a given user id + /// + /// @param[in] uid + /// The user id of the tracing instance. + /// + /// @param[in] threadid + /// The thread id of the tracing instance, in case configuration + /// for a specific thread is needed. + /// + /// @param[out] error + /// Error indicates what went wrong. + /// + /// @param[out] config + /// The actual configuration being used for tracing. + //------------------------------------------------------------------ + virtual void GetTraceConfig(lldb::user_id_t uid, lldb::tid_t threadid, + Error &error, TraceOptions &config) { + error.SetErrorString("Not implemented"); + } + protected: lldb::pid_t m_pid; @@ -307,6 +478,7 @@ NativeWatchpointList m_watchpoint_list; int m_terminal_fd; uint32_t m_stop_id; + lldb::user_id_t m_trace_num; // lldb_private::Host calls should be used to launch a process for debugging, // and Index: include/lldb/Target/Process.h =================================================================== --- include/lldb/Target/Process.h +++ include/lldb/Target/Process.h @@ -56,6 +56,45 @@ 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() {} + + const std::string &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(const std::string ¶ms) { m_trace_params = params; } + + 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. + std::string m_trace_params; +}; + //---------------------------------------------------------------------- // ProcessProperties //---------------------------------------------------------------------- @@ -2764,6 +2803,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(TraceOptions &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, TraceOptions &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: scripts/interface/SBProcess.i =================================================================== --- scripts/interface/SBProcess.i +++ scripts/interface/SBProcess.i @@ -408,6 +408,22 @@ lldb::SBError SaveCore(const char *file_name); + lldb::user_id_t + StartTrace(SBTraceOptions &sboptions, lldb::SBError &sberror, lldb::tid_t thread_id); + + size_t + GetTraceData(lldb::user_id_t uid, SBError &sberror, void *buf, size_t size, size_t offset, lldb::tid_t thread_id); + + size_t + GetMetaData(lldb::user_id_t uid, SBError &sberror, void *buf, size_t size, size_t offset, lldb::tid_t thread_id); + + void + GetTraceConfig(SBTraceOptions &sboptions, lldb::user_id_t uid, SBError &sberror, lldb::tid_t thread_id); + + void + StopTrace(lldb::user_id_t uid, SBError &sberror, lldb::tid_t thread_id); + + lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr, lldb::SBMemoryRegionInfo ®ion_info); Index: scripts/interface/SBTraceOptions.i =================================================================== --- /dev/null +++ scripts/interface/SBTraceOptions.i @@ -0,0 +1,76 @@ +//===-- 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 SBTraceOptions +{ +public: + SBTraceOptions(lldb::TraceType type = lldb::TraceType::eTraceTypeNone, + uint64_t trace_buffer_size = 0, + uint64_t meta_data_buffer_size = 0) : + m_type(type), + m_trace_params(), + m_trace_buffer_size(trace_buffer_size), + m_meta_data_buffer_size(meta_data_buffer_size) + { + } + + lldb::TraceType getType() const + { + return m_type; + } + + uint64_t getTraceBufferSize() const + { + return m_trace_buffer_size; + } + + const char * getTraceParams() + { + return m_trace_params.GetData(); + } + + uint64_t getMetaDataBufferSize() const + { + return m_meta_data_buffer_size; + } + + void setTraceParams(SBStream ¶ms) + { + m_trace_params.Clear(); + if (params.GetData() == NULL) + return; + m_trace_params.Printf("%s", params.GetData()); + } + + 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; + + SBStream m_trace_params; + uint64_t m_trace_buffer_size; + uint64_t m_meta_data_buffer_size; +}; + +} // namespace lldb Index: scripts/lldb.swig =================================================================== --- scripts/lldb.swig +++ scripts/lldb.swig @@ -103,6 +103,7 @@ #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBThreadPlan.h" +#include "lldb/API/SBTraceOptions.h" #include "lldb/API/SBType.h" #include "lldb/API/SBTypeCategory.h" #include "lldb/API/SBTypeEnumMember.h" @@ -186,6 +187,7 @@ %include "./interface/SBThread.i" %include "./interface/SBThreadCollection.i" %include "./interface/SBThreadPlan.i" +%include "./interface/SBTraceOptions.i" %include "./interface/SBType.i" %include "./interface/SBTypeCategory.i" %include "./interface/SBTypeEnumMember.i" Index: source/API/SBProcess.cpp =================================================================== --- source/API/SBProcess.cpp +++ source/API/SBProcess.cpp @@ -44,6 +44,7 @@ #include "lldb/API/SBStructuredData.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBThreadCollection.h" +#include "lldb/API/SBTraceOptions.h" #include "lldb/API/SBUnixSignals.h" using namespace lldb; @@ -349,6 +350,165 @@ return bytes_read; } +void SBProcess::GetTraceConfig(SBTraceOptions &sboptions, lldb::user_id_t uid, + SBError &sberror, lldb::tid_t thread_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + Error error; + ProcessSP process_sp(GetSP()); + sberror.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + sberror.SetErrorString("invalid process"); + } else { + TraceOptions options; + + process_sp->GetTraceConfig(uid, thread_id, error, options); + if (error.Fail()) { + sberror.SetError(error.GetError(), error.GetType()); + sberror.SetErrorString(error.AsCString()); + return; + } + if (log) + log->Printf("SBProcess:: %s returned uid - %" PRIx64, __FUNCTION__, uid); + + sboptions.setTraceBufferSize(options.getTraceBufferSize()); + sboptions.setMetaDataBufferSize(options.getMetaDataBufferSize()); + sboptions.setType(options.getType()); + + const char *params = options.getTraceParams().c_str(); + + if (params) { + SBStream stream_params; + stream_params.Printf("%s", params); + sboptions.setTraceParams(stream_params); + + if (log) + log->Printf("SBProcess:: %s parmeters are - %s ", __FUNCTION__, params); + } + } +} + +lldb::user_id_t SBProcess::StartTrace(SBTraceOptions &sboptions, + lldb::SBError &sberror, + lldb::tid_t thread_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + Error error; + ProcessSP process_sp(GetSP()); + lldb::user_id_t uid = LLDB_INVALID_UID; + sberror.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + sberror.SetErrorString("invalid process"); + } else { + TraceOptions options; + + options.setTraceBufferSize(sboptions.getTraceBufferSize()); + options.setMetaDataBufferSize(sboptions.getMetaDataBufferSize()); + options.setType(sboptions.getType()); + + const char *params = sboptions.getTraceParams(); + if (params) { + options.setTraceParams(params); + if (log) + log->Printf("SBProcess:: %s parmeters are - %s ", __FUNCTION__, params); + } + + uid = process_sp->StartTrace(options, thread_id, error); + if (error.Fail()) { + sberror.SetError(error.GetError(), error.GetType()); + sberror.SetErrorString(error.AsCString()); + } + if (log) + log->Printf("SBProcess:: %s returned uid - %" PRIx64, __FUNCTION__, uid); + } + return uid; +} + +size_t SBProcess::GetTraceData(lldb::user_id_t uid, SBError &sberror, 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)); + sberror.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + sberror.SetErrorString("invalid process"); + } else { + Error error; + bytes_read = process_sp->GetData(uid, thread_id, error, buf, size, offset); + if (error.Fail()) { + sberror.SetError(error.GetError(), error.GetType()); + sberror.SetErrorString(error.AsCString()); + } + if (log) + log->Printf("SBProcess:: %s bytes_read - %" PRIx64, __FUNCTION__, + bytes_read); + } + return bytes_read; +} + +size_t SBProcess::GetMetaData(lldb::user_id_t uid, SBError &sberror, 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)); + sberror.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + sberror.SetErrorString("invalid process"); + } else { + Error error; + bytes_read = + process_sp->GetMetaData(uid, thread_id, error, buf, size, offset); + if (error.Fail()) { + sberror.SetError(error.GetError(), error.GetType()); + sberror.SetErrorString(error.AsCString()); + } + if (log) + log->Printf("SBProcess:: %s bytes_read - %" PRIx64, __FUNCTION__, + bytes_read); + } + return bytes_read; +} + +void SBProcess::StopTrace(lldb::user_id_t uid, SBError &sberror, + lldb::tid_t thread_id) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + ProcessSP process_sp(GetSP()); + sberror.Clear(); + + if (log) + log->Printf("SBProcess:: %s", __FUNCTION__); + + if (!process_sp) { + sberror.SetErrorString("invalid process"); + } else { + Error error; + process_sp->StopTrace(uid, thread_id, error); + if (error.Fail()) { + sberror.SetError(error.GetError(), error.GetType()); + sberror.SetErrorString(error.AsCString()); + if (log) + log->Printf("SBProcess:: %s %" PRIx32, __FUNCTION__, + sberror.GetError()); + } + } +} + void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const { if (out == NULL) return; Index: source/Host/common/NativeProcessProtocol.cpp =================================================================== --- source/Host/common/NativeProcessProtocol.cpp +++ source/Host/common/NativeProcessProtocol.cpp @@ -34,7 +34,7 @@ m_threads_mutex(), m_state(lldb::eStateInvalid), m_state_mutex(), m_exit_type(eExitTypeInvalid), m_exit_status(0), m_exit_description(), m_delegates_mutex(), m_delegates(), m_breakpoint_list(), - m_watchpoint_list(), m_terminal_fd(-1), m_stop_id(0) {} + m_watchpoint_list(), m_terminal_fd(-1), m_stop_id(0), m_trace_num(0) {} lldb_private::Error NativeProcessProtocol::Interrupt() { Error error;