1 //===-- SBTraceOptions.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 "lldb/API/SBTraceOptions.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBError.h"
12 #include "lldb/API/SBStructuredData.h"
13 #include "lldb/Core/StructuredDataImpl.h"
14 #include "lldb/Utility/Log.h"
15 #include "lldb/Utility/TraceOptions.h"
20 using namespace lldb_private
;
22 SBTraceOptions::SBTraceOptions() {
23 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTraceOptions
);
25 m_traceoptions_sp
= std::make_shared
<TraceOptions
>();
28 lldb::TraceType
SBTraceOptions::getType() const {
29 LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::TraceType
, SBTraceOptions
, getType
);
31 if (m_traceoptions_sp
)
32 return m_traceoptions_sp
->getType();
33 return lldb::TraceType::eTraceTypeNone
;
36 uint64_t SBTraceOptions::getTraceBufferSize() const {
37 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint64_t, SBTraceOptions
,
40 if (m_traceoptions_sp
)
41 return m_traceoptions_sp
->getTraceBufferSize();
45 lldb::SBStructuredData
SBTraceOptions::getTraceParams(lldb::SBError
&error
) {
46 LLDB_RECORD_METHOD(lldb::SBStructuredData
, SBTraceOptions
, getTraceParams
,
47 (lldb::SBError
&), error
);
50 const lldb_private::StructuredData::DictionarySP dict_obj
=
51 m_traceoptions_sp
->getTraceParams();
52 lldb::SBStructuredData structData
;
53 if (dict_obj
&& structData
.m_impl_up
)
54 structData
.m_impl_up
->SetObjectSP(dict_obj
->shared_from_this());
56 error
.SetErrorString("Empty trace params");
57 return LLDB_RECORD_RESULT(structData
);
60 uint64_t SBTraceOptions::getMetaDataBufferSize() const {
61 LLDB_RECORD_METHOD_CONST_NO_ARGS(uint64_t, SBTraceOptions
,
62 getMetaDataBufferSize
);
64 if (m_traceoptions_sp
)
65 return m_traceoptions_sp
->getTraceBufferSize();
69 void SBTraceOptions::setTraceParams(lldb::SBStructuredData
¶ms
) {
70 LLDB_RECORD_METHOD(void, SBTraceOptions
, setTraceParams
,
71 (lldb::SBStructuredData
&), params
);
73 if (m_traceoptions_sp
&& params
.m_impl_up
) {
74 StructuredData::ObjectSP obj_sp
= params
.m_impl_up
->GetObjectSP();
75 if (obj_sp
&& obj_sp
->GetAsDictionary() != nullptr)
76 m_traceoptions_sp
->setTraceParams(
77 std::static_pointer_cast
<StructuredData::Dictionary
>(obj_sp
));
82 void SBTraceOptions::setType(lldb::TraceType type
) {
83 LLDB_RECORD_METHOD(void, SBTraceOptions
, setType
, (lldb::TraceType
), type
);
85 if (m_traceoptions_sp
)
86 m_traceoptions_sp
->setType(type
);
89 void SBTraceOptions::setTraceBufferSize(uint64_t size
) {
90 LLDB_RECORD_METHOD(void, SBTraceOptions
, setTraceBufferSize
, (uint64_t),
93 if (m_traceoptions_sp
)
94 m_traceoptions_sp
->setTraceBufferSize(size
);
97 void SBTraceOptions::setMetaDataBufferSize(uint64_t size
) {
98 LLDB_RECORD_METHOD(void, SBTraceOptions
, setMetaDataBufferSize
, (uint64_t),
101 if (m_traceoptions_sp
)
102 m_traceoptions_sp
->setMetaDataBufferSize(size
);
105 bool SBTraceOptions::IsValid() {
106 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTraceOptions
, IsValid
);
107 return this->operator bool();
109 SBTraceOptions::operator bool() const {
110 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTraceOptions
, operator bool);
112 if (m_traceoptions_sp
)
117 void SBTraceOptions::setThreadID(lldb::tid_t thread_id
) {
118 LLDB_RECORD_METHOD(void, SBTraceOptions
, setThreadID
, (lldb::tid_t
),
121 if (m_traceoptions_sp
)
122 m_traceoptions_sp
->setThreadID(thread_id
);
125 lldb::tid_t
SBTraceOptions::getThreadID() {
126 LLDB_RECORD_METHOD_NO_ARGS(lldb::tid_t
, SBTraceOptions
, getThreadID
);
128 if (m_traceoptions_sp
)
129 return m_traceoptions_sp
->getThreadID();
130 return LLDB_INVALID_THREAD_ID
;
133 namespace lldb_private
{
137 void RegisterMethods
<SBTraceOptions
>(Registry
&R
) {
138 LLDB_REGISTER_CONSTRUCTOR(SBTraceOptions
, ());
139 LLDB_REGISTER_METHOD_CONST(lldb::TraceType
, SBTraceOptions
, getType
, ());
140 LLDB_REGISTER_METHOD_CONST(uint64_t, SBTraceOptions
, getTraceBufferSize
,
142 LLDB_REGISTER_METHOD(lldb::SBStructuredData
, SBTraceOptions
, getTraceParams
,
144 LLDB_REGISTER_METHOD_CONST(uint64_t, SBTraceOptions
, getMetaDataBufferSize
,
146 LLDB_REGISTER_METHOD(void, SBTraceOptions
, setTraceParams
,
147 (lldb::SBStructuredData
&));
148 LLDB_REGISTER_METHOD(void, SBTraceOptions
, setType
, (lldb::TraceType
));
149 LLDB_REGISTER_METHOD(void, SBTraceOptions
, setTraceBufferSize
, (uint64_t));
150 LLDB_REGISTER_METHOD(void, SBTraceOptions
, setMetaDataBufferSize
,
152 LLDB_REGISTER_METHOD(bool, SBTraceOptions
, IsValid
, ());
153 LLDB_REGISTER_METHOD_CONST(bool, SBTraceOptions
, operator bool, ());
154 LLDB_REGISTER_METHOD(void, SBTraceOptions
, setThreadID
, (lldb::tid_t
));
155 LLDB_REGISTER_METHOD(lldb::tid_t
, SBTraceOptions
, getThreadID
, ());