1 //===-- SBTrace.cpp ---------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "SBReproducerPrivate.h"
10 #include "lldb/Target/Process.h"
12 #include "lldb/API/SBTrace.h"
13 #include "lldb/API/SBTraceOptions.h"
18 using namespace lldb_private
;
25 lldb::ProcessSP
SBTrace::GetSP() const { return m_opaque_wp
.lock(); }
27 size_t SBTrace::GetTraceData(SBError
&error
, void *buf
, size_t size
,
28 size_t offset
, lldb::tid_t thread_id
) {
29 LLDB_RECORD_DUMMY(size_t, SBTrace
, GetTraceData
,
30 (lldb::SBError
&, void *, size_t, size_t, lldb::tid_t
),
31 error
, buf
, size
, offset
, thread_id
);
33 ProcessSP
process_sp(GetSP());
34 llvm::MutableArrayRef
<uint8_t> buffer(static_cast<uint8_t *>(buf
), size
);
38 error
.SetErrorString("invalid process");
41 process_sp
->GetData(GetTraceUID(), thread_id
, buffer
, offset
));
46 size_t SBTrace::GetMetaData(SBError
&error
, void *buf
, size_t size
,
47 size_t offset
, lldb::tid_t thread_id
) {
48 LLDB_RECORD_DUMMY(size_t, SBTrace
, GetMetaData
,
49 (lldb::SBError
&, void *, size_t, size_t, lldb::tid_t
),
50 error
, buf
, size
, offset
, thread_id
);
52 ProcessSP
process_sp(GetSP());
53 llvm::MutableArrayRef
<uint8_t> buffer(static_cast<uint8_t *>(buf
), size
);
57 error
.SetErrorString("invalid process");
60 process_sp
->GetMetaData(GetTraceUID(), thread_id
, buffer
, offset
));
65 void SBTrace::StopTrace(SBError
&error
, lldb::tid_t thread_id
) {
66 LLDB_RECORD_METHOD(void, SBTrace
, StopTrace
, (lldb::SBError
&, lldb::tid_t
),
69 ProcessSP
process_sp(GetSP());
73 error
.SetErrorString("invalid process");
76 error
.SetError(process_sp
->StopTrace(GetTraceUID(), thread_id
));
79 void SBTrace::GetTraceConfig(SBTraceOptions
&options
, SBError
&error
) {
80 LLDB_RECORD_METHOD(void, SBTrace
, GetTraceConfig
,
81 (lldb::SBTraceOptions
&, lldb::SBError
&), options
, error
);
83 ProcessSP
process_sp(GetSP());
87 error
.SetErrorString("invalid process");
89 error
.SetError(process_sp
->GetTraceConfig(GetTraceUID(),
90 *(options
.m_traceoptions_sp
)));
94 lldb::user_id_t
SBTrace::GetTraceUID() {
95 LLDB_RECORD_METHOD_NO_ARGS(lldb::user_id_t
, SBTrace
, GetTraceUID
);
98 return m_trace_impl_sp
->uid
;
99 return LLDB_INVALID_UID
;
102 void SBTrace::SetTraceUID(lldb::user_id_t uid
) {
104 m_trace_impl_sp
->uid
= uid
;
108 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTrace
);
110 m_trace_impl_sp
= std::make_shared
<TraceImpl
>();
112 m_trace_impl_sp
->uid
= LLDB_INVALID_UID
;
115 void SBTrace::SetSP(const ProcessSP
&process_sp
) { m_opaque_wp
= process_sp
; }
117 bool SBTrace::IsValid() {
118 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTrace
, IsValid
);
119 return this->operator bool();
121 SBTrace::operator bool() const {
122 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTrace
, operator bool);
124 if (!m_trace_impl_sp
)
131 namespace lldb_private
{
135 void RegisterMethods
<SBTrace
>(Registry
&R
) {
136 LLDB_REGISTER_METHOD(void, SBTrace
, StopTrace
,
137 (lldb::SBError
&, lldb::tid_t
));
138 LLDB_REGISTER_METHOD(void, SBTrace
, GetTraceConfig
,
139 (lldb::SBTraceOptions
&, lldb::SBError
&));
140 LLDB_REGISTER_METHOD(lldb::user_id_t
, SBTrace
, GetTraceUID
, ());
141 LLDB_REGISTER_CONSTRUCTOR(SBTrace
, ());
142 LLDB_REGISTER_METHOD(bool, SBTrace
, IsValid
, ());
143 LLDB_REGISTER_METHOD_CONST(bool, SBTrace
, operator bool, ());