blob: 18f7d36e775921e498529887a2297578c494f0ed [file] [log] [blame]
Ravitheja Addepallyd5d8d912017-04-26 08:48:50 +00001//===-- SBTrace.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Utility/Log.h"
11#include "lldb/Target/Process.h"
12
13#include "lldb/API/SBTrace.h"
14#include "lldb/API/SBTraceOptions.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
19class TraceImpl {
20public:
21 lldb::user_id_t uid;
22};
23
24lldb::ProcessSP SBTrace::GetSP() const { return m_opaque_wp.lock(); }
25
26size_t SBTrace::GetTraceData(SBError &error, void *buf, size_t size,
27 size_t offset, lldb::tid_t thread_id) {
28 size_t bytes_read = 0;
29 ProcessSP process_sp(GetSP());
30 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
31 error.Clear();
32
33 if (!process_sp) {
34 error.SetErrorString("invalid process");
35 } else {
36 bytes_read = process_sp->GetData(GetTraceUID(), thread_id, error.ref(), buf,
37 size, offset);
38 LLDB_LOG(log, "SBTrace::bytes_read - %" PRIx64, bytes_read);
39 }
40 return bytes_read;
41}
42
43size_t SBTrace::GetMetaData(SBError &error, void *buf, size_t size,
44 size_t offset, lldb::tid_t thread_id) {
45 size_t bytes_read = 0;
46 ProcessSP process_sp(GetSP());
47 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
48 error.Clear();
49
50 if (!process_sp) {
51 error.SetErrorString("invalid process");
52 } else {
53
54 bytes_read = process_sp->GetMetaData(GetTraceUID(), thread_id, error.ref(),
55 buf, size, offset);
56 LLDB_LOG(log, "SBTrace::bytes_read - %" PRIx64, bytes_read);
57 }
58 return bytes_read;
59}
60
61void SBTrace::StopTrace(SBError &error, lldb::tid_t thread_id) {
62 ProcessSP process_sp(GetSP());
63 error.Clear();
64
65 if (!process_sp) {
66 error.SetErrorString("invalid process");
67 return;
68 }
69 process_sp->StopTrace(GetTraceUID(), thread_id, error.ref());
70}
71
72void SBTrace::GetTraceConfig(SBTraceOptions &options, SBError &error) {
73 ProcessSP process_sp(GetSP());
74 error.Clear();
75
76 if (!process_sp) {
77 error.SetErrorString("invalid process");
78 } else {
79 process_sp->GetTraceConfig(GetTraceUID(), error.ref(),
80 options.m_traceoptions_sp);
81 }
82}
83
84lldb::user_id_t SBTrace::GetTraceUID() {
85 if (m_trace_impl_sp)
86 return m_trace_impl_sp->uid;
87 return LLDB_INVALID_UID;
88}
89
90void SBTrace::SetTraceUID(lldb::user_id_t uid) {
91 if (m_trace_impl_sp)
92 m_trace_impl_sp->uid = uid;
93}
94
95SBTrace::SBTrace() {
96 m_trace_impl_sp.reset(new TraceImpl);
97 if (m_trace_impl_sp)
98 m_trace_impl_sp->uid = LLDB_INVALID_UID;
99}
100
101void SBTrace::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
102
103bool SBTrace::IsValid() {
104 if (!m_trace_impl_sp)
105 return false;
106 if (!GetSP())
107 return false;
108 return true;
109}