1 //===-- SBExpressionOptions.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/SBExpressionOptions.h"
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Target/Target.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 SBExpressionOptions::SBExpressionOptions()
19     : m_opaque_up(new EvaluateExpressionOptions()) {
20   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBExpressionOptions);
21 }
22 
23 SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs)
24     : m_opaque_up() {
25   LLDB_RECORD_CONSTRUCTOR(SBExpressionOptions,
26                           (const lldb::SBExpressionOptions &), rhs);
27 
28   m_opaque_up = clone(rhs.m_opaque_up);
29 }
30 
31 const SBExpressionOptions &SBExpressionOptions::
32 operator=(const SBExpressionOptions &rhs) {
33   LLDB_RECORD_METHOD(
34       const lldb::SBExpressionOptions &,
35       SBExpressionOptions, operator=,(const lldb::SBExpressionOptions &), rhs);
36 
37   if (this != &rhs)
38     m_opaque_up = clone(rhs.m_opaque_up);
39   return LLDB_RECORD_RESULT(*this);
40 }
41 
42 SBExpressionOptions::~SBExpressionOptions() {}
43 
44 bool SBExpressionOptions::GetCoerceResultToId() const {
45   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
46                                    GetCoerceResultToId);
47 
48   return m_opaque_up->DoesCoerceToId();
49 }
50 
51 void SBExpressionOptions::SetCoerceResultToId(bool coerce) {
52   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetCoerceResultToId, (bool),
53                      coerce);
54 
55   m_opaque_up->SetCoerceToId(coerce);
56 }
57 
58 bool SBExpressionOptions::GetUnwindOnError() const {
59   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetUnwindOnError);
60 
61   return m_opaque_up->DoesUnwindOnError();
62 }
63 
64 void SBExpressionOptions::SetUnwindOnError(bool unwind) {
65   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetUnwindOnError, (bool),
66                      unwind);
67 
68   m_opaque_up->SetUnwindOnError(unwind);
69 }
70 
71 bool SBExpressionOptions::GetIgnoreBreakpoints() const {
72   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
73                                    GetIgnoreBreakpoints);
74 
75   return m_opaque_up->DoesIgnoreBreakpoints();
76 }
77 
78 void SBExpressionOptions::SetIgnoreBreakpoints(bool ignore) {
79   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetIgnoreBreakpoints, (bool),
80                      ignore);
81 
82   m_opaque_up->SetIgnoreBreakpoints(ignore);
83 }
84 
85 lldb::DynamicValueType SBExpressionOptions::GetFetchDynamicValue() const {
86   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::DynamicValueType, SBExpressionOptions,
87                                    GetFetchDynamicValue);
88 
89   return m_opaque_up->GetUseDynamic();
90 }
91 
92 void SBExpressionOptions::SetFetchDynamicValue(lldb::DynamicValueType dynamic) {
93   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetFetchDynamicValue,
94                      (lldb::DynamicValueType), dynamic);
95 
96   m_opaque_up->SetUseDynamic(dynamic);
97 }
98 
99 uint32_t SBExpressionOptions::GetTimeoutInMicroSeconds() const {
100   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBExpressionOptions,
101                                    GetTimeoutInMicroSeconds);
102 
103   return m_opaque_up->GetTimeout() ? m_opaque_up->GetTimeout()->count() : 0;
104 }
105 
106 void SBExpressionOptions::SetTimeoutInMicroSeconds(uint32_t timeout) {
107   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTimeoutInMicroSeconds,
108                      (uint32_t), timeout);
109 
110   m_opaque_up->SetTimeout(timeout == 0 ? Timeout<std::micro>(llvm::None)
111                                        : std::chrono::microseconds(timeout));
112 }
113 
114 uint32_t SBExpressionOptions::GetOneThreadTimeoutInMicroSeconds() const {
115   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBExpressionOptions,
116                                    GetOneThreadTimeoutInMicroSeconds);
117 
118   return m_opaque_up->GetOneThreadTimeout()
119              ? m_opaque_up->GetOneThreadTimeout()->count()
120              : 0;
121 }
122 
123 void SBExpressionOptions::SetOneThreadTimeoutInMicroSeconds(uint32_t timeout) {
124   LLDB_RECORD_METHOD(void, SBExpressionOptions,
125                      SetOneThreadTimeoutInMicroSeconds, (uint32_t), timeout);
126 
127   m_opaque_up->SetOneThreadTimeout(timeout == 0
128                                        ? Timeout<std::micro>(llvm::None)
129                                        : std::chrono::microseconds(timeout));
130 }
131 
132 bool SBExpressionOptions::GetTryAllThreads() const {
133   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetTryAllThreads);
134 
135   return m_opaque_up->GetTryAllThreads();
136 }
137 
138 void SBExpressionOptions::SetTryAllThreads(bool run_others) {
139   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTryAllThreads, (bool),
140                      run_others);
141 
142   m_opaque_up->SetTryAllThreads(run_others);
143 }
144 
145 bool SBExpressionOptions::GetStopOthers() const {
146   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetStopOthers);
147 
148   return m_opaque_up->GetStopOthers();
149 }
150 
151 void SBExpressionOptions::SetStopOthers(bool run_others) {
152   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetStopOthers, (bool),
153                      run_others);
154 
155   m_opaque_up->SetStopOthers(run_others);
156 }
157 
158 bool SBExpressionOptions::GetTrapExceptions() const {
159   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
160                                    GetTrapExceptions);
161 
162   return m_opaque_up->GetTrapExceptions();
163 }
164 
165 void SBExpressionOptions::SetTrapExceptions(bool trap_exceptions) {
166   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTrapExceptions, (bool),
167                      trap_exceptions);
168 
169   m_opaque_up->SetTrapExceptions(trap_exceptions);
170 }
171 
172 void SBExpressionOptions::SetLanguage(lldb::LanguageType language) {
173   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetLanguage,
174                      (lldb::LanguageType), language);
175 
176   m_opaque_up->SetLanguage(language);
177 }
178 
179 void SBExpressionOptions::SetCancelCallback(
180     lldb::ExpressionCancelCallback callback, void *baton) {
181   LLDB_RECORD_DUMMY(void, SBExpressionOptions, SetCancelCallback,
182                     (lldb::ExpressionCancelCallback, void *), callback, baton);
183 
184   m_opaque_up->SetCancelCallback(callback, baton);
185 }
186 
187 bool SBExpressionOptions::GetGenerateDebugInfo() {
188   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetGenerateDebugInfo);
189 
190   return m_opaque_up->GetGenerateDebugInfo();
191 }
192 
193 void SBExpressionOptions::SetGenerateDebugInfo(bool b) {
194   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetGenerateDebugInfo, (bool),
195                      b);
196 
197   return m_opaque_up->SetGenerateDebugInfo(b);
198 }
199 
200 bool SBExpressionOptions::GetSuppressPersistentResult() {
201   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions,
202                              GetSuppressPersistentResult);
203 
204   return m_opaque_up->GetResultIsInternal();
205 }
206 
207 void SBExpressionOptions::SetSuppressPersistentResult(bool b) {
208   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetSuppressPersistentResult,
209                      (bool), b);
210 
211   return m_opaque_up->SetResultIsInternal(b);
212 }
213 
214 const char *SBExpressionOptions::GetPrefix() const {
215   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBExpressionOptions,
216                                    GetPrefix);
217 
218   return m_opaque_up->GetPrefix();
219 }
220 
221 void SBExpressionOptions::SetPrefix(const char *prefix) {
222   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetPrefix, (const char *),
223                      prefix);
224 
225   return m_opaque_up->SetPrefix(prefix);
226 }
227 
228 bool SBExpressionOptions::GetAutoApplyFixIts() {
229   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetAutoApplyFixIts);
230 
231   return m_opaque_up->GetAutoApplyFixIts();
232 }
233 
234 void SBExpressionOptions::SetAutoApplyFixIts(bool b) {
235   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetAutoApplyFixIts, (bool), b);
236 
237   return m_opaque_up->SetAutoApplyFixIts(b);
238 }
239 
240 bool SBExpressionOptions::GetTopLevel() {
241   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetTopLevel);
242 
243   return m_opaque_up->GetExecutionPolicy() == eExecutionPolicyTopLevel;
244 }
245 
246 void SBExpressionOptions::SetTopLevel(bool b) {
247   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTopLevel, (bool), b);
248 
249   m_opaque_up->SetExecutionPolicy(b ? eExecutionPolicyTopLevel
250                                     : m_opaque_up->default_execution_policy);
251 }
252 
253 bool SBExpressionOptions::GetAllowJIT() {
254   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetAllowJIT);
255 
256   return m_opaque_up->GetExecutionPolicy() != eExecutionPolicyNever;
257 }
258 
259 void SBExpressionOptions::SetAllowJIT(bool allow) {
260   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetAllowJIT, (bool), allow);
261 
262   m_opaque_up->SetExecutionPolicy(allow ? m_opaque_up->default_execution_policy
263                                         : eExecutionPolicyNever);
264 }
265 
266 EvaluateExpressionOptions *SBExpressionOptions::get() const {
267   return m_opaque_up.get();
268 }
269 
270 EvaluateExpressionOptions &SBExpressionOptions::ref() const {
271   return *(m_opaque_up.get());
272 }
273 
274 namespace lldb_private {
275 namespace repro {
276 
277 template <>
278 void RegisterMethods<SBExpressionOptions>(Registry &R) {
279   LLDB_REGISTER_CONSTRUCTOR(SBExpressionOptions, ());
280   LLDB_REGISTER_CONSTRUCTOR(SBExpressionOptions,
281                             (const lldb::SBExpressionOptions &));
282   LLDB_REGISTER_METHOD(
283       const lldb::SBExpressionOptions &,
284       SBExpressionOptions, operator=,(const lldb::SBExpressionOptions &));
285   LLDB_REGISTER_METHOD_CONST(bool, SBExpressionOptions, GetCoerceResultToId,
286                              ());
287   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetCoerceResultToId,
288                        (bool));
289   LLDB_REGISTER_METHOD_CONST(bool, SBExpressionOptions, GetUnwindOnError, ());
290   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetUnwindOnError, (bool));
291   LLDB_REGISTER_METHOD_CONST(bool, SBExpressionOptions, GetIgnoreBreakpoints,
292                              ());
293   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetIgnoreBreakpoints,
294                        (bool));
295   LLDB_REGISTER_METHOD_CONST(lldb::DynamicValueType, SBExpressionOptions,
296                              GetFetchDynamicValue, ());
297   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetFetchDynamicValue,
298                        (lldb::DynamicValueType));
299   LLDB_REGISTER_METHOD_CONST(uint32_t, SBExpressionOptions,
300                              GetTimeoutInMicroSeconds, ());
301   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetTimeoutInMicroSeconds,
302                        (uint32_t));
303   LLDB_REGISTER_METHOD_CONST(uint32_t, SBExpressionOptions,
304                              GetOneThreadTimeoutInMicroSeconds, ());
305   LLDB_REGISTER_METHOD(void, SBExpressionOptions,
306                        SetOneThreadTimeoutInMicroSeconds, (uint32_t));
307   LLDB_REGISTER_METHOD_CONST(bool, SBExpressionOptions, GetTryAllThreads, ());
308   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetTryAllThreads, (bool));
309   LLDB_REGISTER_METHOD_CONST(bool, SBExpressionOptions, GetStopOthers, ());
310   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetStopOthers, (bool));
311   LLDB_REGISTER_METHOD_CONST(bool, SBExpressionOptions, GetTrapExceptions,
312                              ());
313   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetTrapExceptions, (bool));
314   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetLanguage,
315                        (lldb::LanguageType));
316   LLDB_REGISTER_METHOD(bool, SBExpressionOptions, GetGenerateDebugInfo, ());
317   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetGenerateDebugInfo,
318                        (bool));
319   LLDB_REGISTER_METHOD(bool, SBExpressionOptions, GetSuppressPersistentResult,
320                        ());
321   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetSuppressPersistentResult,
322                        (bool));
323   LLDB_REGISTER_METHOD_CONST(const char *, SBExpressionOptions, GetPrefix,
324                              ());
325   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetPrefix, (const char *));
326   LLDB_REGISTER_METHOD(bool, SBExpressionOptions, GetAutoApplyFixIts, ());
327   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetAutoApplyFixIts, (bool));
328   LLDB_REGISTER_METHOD(bool, SBExpressionOptions, GetTopLevel, ());
329   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetTopLevel, (bool));
330   LLDB_REGISTER_METHOD(bool, SBExpressionOptions, GetAllowJIT, ());
331   LLDB_REGISTER_METHOD(void, SBExpressionOptions, SetAllowJIT, (bool));
332 }
333 
334 }
335 }
336