summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBTrace.cpp
diff options
context:
space:
mode:
authorRavitheja Addepally <ravitheja.addepally@intel.com>2017-04-26 08:48:50 +0000
committerRavitheja Addepally <ravitheja.addepally@intel.com>2017-04-26 08:48:50 +0000
commitd5d8d91c1db18b984adb43632a1832202a0ecf1b (patch)
tree7391e1acfc7b953e755552c21ed20778ade191f1 /lldb/source/API/SBTrace.cpp
parent2bcd94f8d8959a523adf8211c57a94782d561ca5 (diff)
downloadbcm5719-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/SBTrace.cpp')
-rw-r--r--lldb/source/API/SBTrace.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/lldb/source/API/SBTrace.cpp b/lldb/source/API/SBTrace.cpp
new file mode 100644
index 00000000000..18f7d36e775
--- /dev/null
+++ b/lldb/source/API/SBTrace.cpp
@@ -0,0 +1,109 @@
+//===-- 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/Utility/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 TraceImpl {
+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 (!process_sp) {
+ error.SetErrorString("invalid process");
+ } else {
+ bytes_read = process_sp->GetData(GetTraceUID(), thread_id, error.ref(), buf,
+ size, offset);
+ LLDB_LOG(log, "SBTrace::bytes_read - %" PRIx64, 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 (!process_sp) {
+ error.SetErrorString("invalid process");
+ } else {
+
+ bytes_read = process_sp->GetMetaData(GetTraceUID(), thread_id, error.ref(),
+ buf, size, offset);
+ LLDB_LOG(log, "SBTrace::bytes_read - %" PRIx64, bytes_read);
+ }
+ return bytes_read;
+}
+
+void SBTrace::StopTrace(SBError &error, lldb::tid_t thread_id) {
+ ProcessSP process_sp(GetSP());
+ error.Clear();
+
+ if (!process_sp) {
+ error.SetErrorString("invalid process");
+ return;
+ }
+ process_sp->StopTrace(GetTraceUID(), thread_id, error.ref());
+}
+
+void SBTrace::GetTraceConfig(SBTraceOptions &options, SBError &error) {
+ ProcessSP process_sp(GetSP());
+ error.Clear();
+
+ if (!process_sp) {
+ error.SetErrorString("invalid process");
+ } else {
+ process_sp->GetTraceConfig(GetTraceUID(), 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 TraceImpl);
+ 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;
+}
OpenPOWER on IntegriCloud