1 //===-- SBVariablesOptions.cpp --------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/API/SBVariablesOptions.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBTarget.h"
12 #include "lldb/Target/Target.h"
13 
14 #include "lldb/lldb-private.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 class VariablesOptionsImpl {
20 public:
21   VariablesOptionsImpl()
22       : m_include_arguments(false), m_include_locals(false),
23         m_include_statics(false), m_in_scope_only(false),
24         m_include_runtime_support_values(false) {}
25 
26   VariablesOptionsImpl(const VariablesOptionsImpl &) = default;
27 
28   ~VariablesOptionsImpl() = default;
29 
30   VariablesOptionsImpl &operator=(const VariablesOptionsImpl &) = default;
31 
32   bool GetIncludeArguments() const { return m_include_arguments; }
33 
34   void SetIncludeArguments(bool b) { m_include_arguments = b; }
35 
36   bool GetIncludeRecognizedArguments(const lldb::TargetSP &target_sp) const {
37     if (m_include_recognized_arguments != eLazyBoolCalculate)
38         return m_include_recognized_arguments;
39     return target_sp ? target_sp->GetDisplayRecognizedArguments() : false;
40   }
41 
42   void SetIncludeRecognizedArguments(bool b) {
43     m_include_recognized_arguments = b ? eLazyBoolYes : eLazyBoolNo;
44   }
45 
46   bool GetIncludeLocals() const { return m_include_locals; }
47 
48   void SetIncludeLocals(bool b) { m_include_locals = b; }
49 
50   bool GetIncludeStatics() const { return m_include_statics; }
51 
52   void SetIncludeStatics(bool b) { m_include_statics = b; }
53 
54   bool GetInScopeOnly() const { return m_in_scope_only; }
55 
56   void SetInScopeOnly(bool b) { m_in_scope_only = b; }
57 
58   bool GetIncludeRuntimeSupportValues() const {
59     return m_include_runtime_support_values;
60   }
61 
62   void SetIncludeRuntimeSupportValues(bool b) {
63     m_include_runtime_support_values = b;
64   }
65 
66   lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
67 
68   void SetUseDynamic(lldb::DynamicValueType d) { m_use_dynamic = d; }
69 
70 private:
71   bool m_include_arguments : 1;
72   bool m_include_locals : 1;
73   bool m_include_statics : 1;
74   bool m_in_scope_only : 1;
75   bool m_include_runtime_support_values : 1;
76   LazyBool m_include_recognized_arguments =
77       eLazyBoolCalculate; // can be overridden with a setting
78   lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues;
79 };
80 
81 SBVariablesOptions::SBVariablesOptions()
82     : m_opaque_up(new VariablesOptionsImpl()) {
83   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBVariablesOptions);
84 }
85 
86 SBVariablesOptions::SBVariablesOptions(const SBVariablesOptions &options)
87     : m_opaque_up(new VariablesOptionsImpl(options.ref())) {
88   LLDB_RECORD_CONSTRUCTOR(SBVariablesOptions,
89                           (const lldb::SBVariablesOptions &), options);
90 }
91 
92 SBVariablesOptions &SBVariablesOptions::
93 operator=(const SBVariablesOptions &options) {
94   LLDB_RECORD_METHOD(
95       lldb::SBVariablesOptions &,
96       SBVariablesOptions, operator=,(const lldb::SBVariablesOptions &),
97       options);
98 
99   m_opaque_up = std::make_unique<VariablesOptionsImpl>(options.ref());
100   return LLDB_RECORD_RESULT(*this);
101 }
102 
103 SBVariablesOptions::~SBVariablesOptions() = default;
104 
105 bool SBVariablesOptions::IsValid() const {
106   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions, IsValid);
107   return this->operator bool();
108 }
109 SBVariablesOptions::operator bool() const {
110   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions, operator bool);
111 
112   return m_opaque_up != nullptr;
113 }
114 
115 bool SBVariablesOptions::GetIncludeArguments() const {
116   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions,
117                                    GetIncludeArguments);
118 
119   return m_opaque_up->GetIncludeArguments();
120 }
121 
122 void SBVariablesOptions::SetIncludeArguments(bool arguments) {
123   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetIncludeArguments, (bool),
124                      arguments);
125 
126   m_opaque_up->SetIncludeArguments(arguments);
127 }
128 
129 bool SBVariablesOptions::GetIncludeRecognizedArguments(
130     const lldb::SBTarget &target) const {
131   LLDB_RECORD_METHOD_CONST(bool, SBVariablesOptions,
132                            GetIncludeRecognizedArguments,
133                            (const lldb::SBTarget &), target);
134 
135   return m_opaque_up->GetIncludeRecognizedArguments(target.GetSP());
136 }
137 
138 void SBVariablesOptions::SetIncludeRecognizedArguments(bool arguments) {
139   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetIncludeRecognizedArguments,
140                      (bool), arguments);
141 
142   m_opaque_up->SetIncludeRecognizedArguments(arguments);
143 }
144 
145 bool SBVariablesOptions::GetIncludeLocals() const {
146   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions, GetIncludeLocals);
147 
148   return m_opaque_up->GetIncludeLocals();
149 }
150 
151 void SBVariablesOptions::SetIncludeLocals(bool locals) {
152   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetIncludeLocals, (bool),
153                      locals);
154 
155   m_opaque_up->SetIncludeLocals(locals);
156 }
157 
158 bool SBVariablesOptions::GetIncludeStatics() const {
159   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions, GetIncludeStatics);
160 
161   return m_opaque_up->GetIncludeStatics();
162 }
163 
164 void SBVariablesOptions::SetIncludeStatics(bool statics) {
165   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetIncludeStatics, (bool),
166                      statics);
167 
168   m_opaque_up->SetIncludeStatics(statics);
169 }
170 
171 bool SBVariablesOptions::GetInScopeOnly() const {
172   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions, GetInScopeOnly);
173 
174   return m_opaque_up->GetInScopeOnly();
175 }
176 
177 void SBVariablesOptions::SetInScopeOnly(bool in_scope_only) {
178   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetInScopeOnly, (bool),
179                      in_scope_only);
180 
181   m_opaque_up->SetInScopeOnly(in_scope_only);
182 }
183 
184 bool SBVariablesOptions::GetIncludeRuntimeSupportValues() const {
185   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBVariablesOptions,
186                                    GetIncludeRuntimeSupportValues);
187 
188   return m_opaque_up->GetIncludeRuntimeSupportValues();
189 }
190 
191 void SBVariablesOptions::SetIncludeRuntimeSupportValues(
192     bool runtime_support_values) {
193   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetIncludeRuntimeSupportValues,
194                      (bool), runtime_support_values);
195 
196   m_opaque_up->SetIncludeRuntimeSupportValues(runtime_support_values);
197 }
198 
199 lldb::DynamicValueType SBVariablesOptions::GetUseDynamic() const {
200   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::DynamicValueType, SBVariablesOptions,
201                                    GetUseDynamic);
202 
203   return m_opaque_up->GetUseDynamic();
204 }
205 
206 void SBVariablesOptions::SetUseDynamic(lldb::DynamicValueType dynamic) {
207   LLDB_RECORD_METHOD(void, SBVariablesOptions, SetUseDynamic,
208                      (lldb::DynamicValueType), dynamic);
209 
210   m_opaque_up->SetUseDynamic(dynamic);
211 }
212 
213 VariablesOptionsImpl *SBVariablesOptions::operator->() {
214   return m_opaque_up.operator->();
215 }
216 
217 const VariablesOptionsImpl *SBVariablesOptions::operator->() const {
218   return m_opaque_up.operator->();
219 }
220 
221 VariablesOptionsImpl *SBVariablesOptions::get() { return m_opaque_up.get(); }
222 
223 VariablesOptionsImpl &SBVariablesOptions::ref() { return *m_opaque_up; }
224 
225 const VariablesOptionsImpl &SBVariablesOptions::ref() const {
226   return *m_opaque_up;
227 }
228 
229 SBVariablesOptions::SBVariablesOptions(VariablesOptionsImpl *lldb_object_ptr)
230     : m_opaque_up(std::move(lldb_object_ptr)) {}
231 
232 void SBVariablesOptions::SetOptions(VariablesOptionsImpl *lldb_object_ptr) {
233   m_opaque_up.reset(std::move(lldb_object_ptr));
234 }
235 
236 namespace lldb_private {
237 namespace repro {
238 
239 template <>
240 void RegisterMethods<SBVariablesOptions>(Registry &R) {
241   LLDB_REGISTER_CONSTRUCTOR(SBVariablesOptions, ());
242   LLDB_REGISTER_CONSTRUCTOR(SBVariablesOptions,
243                             (const lldb::SBVariablesOptions &));
244   LLDB_REGISTER_METHOD(
245       lldb::SBVariablesOptions &,
246       SBVariablesOptions, operator=,(const lldb::SBVariablesOptions &));
247   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions, IsValid, ());
248   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions, operator bool, ());
249   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions, GetIncludeArguments,
250                              ());
251   LLDB_REGISTER_METHOD(void, SBVariablesOptions, SetIncludeArguments, (bool));
252   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions,
253                              GetIncludeRecognizedArguments,
254                              (const lldb::SBTarget &));
255   LLDB_REGISTER_METHOD(void, SBVariablesOptions,
256                        SetIncludeRecognizedArguments, (bool));
257   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions, GetIncludeLocals, ());
258   LLDB_REGISTER_METHOD(void, SBVariablesOptions, SetIncludeLocals, (bool));
259   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions, GetIncludeStatics, ());
260   LLDB_REGISTER_METHOD(void, SBVariablesOptions, SetIncludeStatics, (bool));
261   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions, GetInScopeOnly, ());
262   LLDB_REGISTER_METHOD(void, SBVariablesOptions, SetInScopeOnly, (bool));
263   LLDB_REGISTER_METHOD_CONST(bool, SBVariablesOptions,
264                              GetIncludeRuntimeSupportValues, ());
265   LLDB_REGISTER_METHOD(void, SBVariablesOptions,
266                        SetIncludeRuntimeSupportValues, (bool));
267   LLDB_REGISTER_METHOD_CONST(lldb::DynamicValueType, SBVariablesOptions,
268                              GetUseDynamic, ());
269   LLDB_REGISTER_METHOD(void, SBVariablesOptions, SetUseDynamic,
270                        (lldb::DynamicValueType));
271 }
272 
273 }
274 }
275