1b9c1b51eSKate Stone //===-- SBExpressionOptions.cpp ---------------------------------------------*-
2b9c1b51eSKate Stone //C++ -*-===//
335e1bda6SJim Ingham //
42946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
52946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
62946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
735e1bda6SJim Ingham //
835e1bda6SJim Ingham //===----------------------------------------------------------------------===//
935e1bda6SJim Ingham 
1035e1bda6SJim Ingham #include "lldb/API/SBExpressionOptions.h"
11*baf5664fSJonas Devlieghere #include "SBReproducerPrivate.h"
12bd4bf82aSJonas Devlieghere #include "Utils.h"
1335e1bda6SJim Ingham #include "lldb/API/SBStream.h"
1435e1bda6SJim Ingham #include "lldb/Target/Target.h"
1535e1bda6SJim Ingham 
1635e1bda6SJim Ingham using namespace lldb;
1735e1bda6SJim Ingham using namespace lldb_private;
1835e1bda6SJim Ingham 
19b9c1b51eSKate Stone SBExpressionOptions::SBExpressionOptions()
20*baf5664fSJonas Devlieghere     : m_opaque_up(new EvaluateExpressionOptions()) {
21*baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBExpressionOptions);
22*baf5664fSJonas Devlieghere }
2335e1bda6SJim Ingham 
24bd4bf82aSJonas Devlieghere SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs)
25bd4bf82aSJonas Devlieghere     : m_opaque_up() {
26*baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBExpressionOptions,
27*baf5664fSJonas Devlieghere                           (const lldb::SBExpressionOptions &), rhs);
28*baf5664fSJonas Devlieghere 
29bd4bf82aSJonas Devlieghere   m_opaque_up = clone(rhs.m_opaque_up);
3035e1bda6SJim Ingham }
3135e1bda6SJim Ingham 
32b9c1b51eSKate Stone const SBExpressionOptions &SBExpressionOptions::
33b9c1b51eSKate Stone operator=(const SBExpressionOptions &rhs) {
34*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(
35*baf5664fSJonas Devlieghere       const lldb::SBExpressionOptions &,
36*baf5664fSJonas Devlieghere       SBExpressionOptions, operator=,(const lldb::SBExpressionOptions &), rhs);
37*baf5664fSJonas Devlieghere 
38bd4bf82aSJonas Devlieghere   if (this != &rhs)
39bd4bf82aSJonas Devlieghere     m_opaque_up = clone(rhs.m_opaque_up);
4035e1bda6SJim Ingham   return *this;
4135e1bda6SJim Ingham }
4235e1bda6SJim Ingham 
43b9c1b51eSKate Stone SBExpressionOptions::~SBExpressionOptions() {}
4435e1bda6SJim Ingham 
45b9c1b51eSKate Stone bool SBExpressionOptions::GetCoerceResultToId() const {
46*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
47*baf5664fSJonas Devlieghere                                    GetCoerceResultToId);
48*baf5664fSJonas Devlieghere 
49d5b44036SJonas Devlieghere   return m_opaque_up->DoesCoerceToId();
5035e1bda6SJim Ingham }
5135e1bda6SJim Ingham 
52b9c1b51eSKate Stone void SBExpressionOptions::SetCoerceResultToId(bool coerce) {
53*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetCoerceResultToId, (bool),
54*baf5664fSJonas Devlieghere                      coerce);
55*baf5664fSJonas Devlieghere 
56d5b44036SJonas Devlieghere   m_opaque_up->SetCoerceToId(coerce);
5735e1bda6SJim Ingham }
5835e1bda6SJim Ingham 
59b9c1b51eSKate Stone bool SBExpressionOptions::GetUnwindOnError() const {
60*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetUnwindOnError);
61*baf5664fSJonas Devlieghere 
62d5b44036SJonas Devlieghere   return m_opaque_up->DoesUnwindOnError();
6335e1bda6SJim Ingham }
6435e1bda6SJim Ingham 
65b9c1b51eSKate Stone void SBExpressionOptions::SetUnwindOnError(bool unwind) {
66*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetUnwindOnError, (bool),
67*baf5664fSJonas Devlieghere                      unwind);
68*baf5664fSJonas Devlieghere 
69d5b44036SJonas Devlieghere   m_opaque_up->SetUnwindOnError(unwind);
7035e1bda6SJim Ingham }
7135e1bda6SJim Ingham 
72b9c1b51eSKate Stone bool SBExpressionOptions::GetIgnoreBreakpoints() const {
73*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
74*baf5664fSJonas Devlieghere                                    GetIgnoreBreakpoints);
75*baf5664fSJonas Devlieghere 
76d5b44036SJonas Devlieghere   return m_opaque_up->DoesIgnoreBreakpoints();
77184e9811SJim Ingham }
78184e9811SJim Ingham 
79b9c1b51eSKate Stone void SBExpressionOptions::SetIgnoreBreakpoints(bool ignore) {
80*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetIgnoreBreakpoints, (bool),
81*baf5664fSJonas Devlieghere                      ignore);
82*baf5664fSJonas Devlieghere 
83d5b44036SJonas Devlieghere   m_opaque_up->SetIgnoreBreakpoints(ignore);
84184e9811SJim Ingham }
85184e9811SJim Ingham 
86b9c1b51eSKate Stone lldb::DynamicValueType SBExpressionOptions::GetFetchDynamicValue() const {
87*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::DynamicValueType, SBExpressionOptions,
88*baf5664fSJonas Devlieghere                                    GetFetchDynamicValue);
89*baf5664fSJonas Devlieghere 
90d5b44036SJonas Devlieghere   return m_opaque_up->GetUseDynamic();
9135e1bda6SJim Ingham }
9235e1bda6SJim Ingham 
93b9c1b51eSKate Stone void SBExpressionOptions::SetFetchDynamicValue(lldb::DynamicValueType dynamic) {
94*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetFetchDynamicValue,
95*baf5664fSJonas Devlieghere                      (lldb::DynamicValueType), dynamic);
96*baf5664fSJonas Devlieghere 
97d5b44036SJonas Devlieghere   m_opaque_up->SetUseDynamic(dynamic);
9835e1bda6SJim Ingham }
9935e1bda6SJim Ingham 
100b9c1b51eSKate Stone uint32_t SBExpressionOptions::GetTimeoutInMicroSeconds() const {
101*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBExpressionOptions,
102*baf5664fSJonas Devlieghere                                    GetTimeoutInMicroSeconds);
103*baf5664fSJonas Devlieghere 
104d5b44036SJonas Devlieghere   return m_opaque_up->GetTimeout() ? m_opaque_up->GetTimeout()->count() : 0;
10535e1bda6SJim Ingham }
10635e1bda6SJim Ingham 
107b9c1b51eSKate Stone void SBExpressionOptions::SetTimeoutInMicroSeconds(uint32_t timeout) {
108*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTimeoutInMicroSeconds,
109*baf5664fSJonas Devlieghere                      (uint32_t), timeout);
110*baf5664fSJonas Devlieghere 
111d5b44036SJonas Devlieghere   m_opaque_up->SetTimeout(timeout == 0 ? Timeout<std::micro>(llvm::None)
11243d35418SPavel Labath                                        : std::chrono::microseconds(timeout));
11335e1bda6SJim Ingham }
11435e1bda6SJim Ingham 
115b9c1b51eSKate Stone uint32_t SBExpressionOptions::GetOneThreadTimeoutInMicroSeconds() const {
116*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBExpressionOptions,
117*baf5664fSJonas Devlieghere                                    GetOneThreadTimeoutInMicroSeconds);
118*baf5664fSJonas Devlieghere 
119d5b44036SJonas Devlieghere   return m_opaque_up->GetOneThreadTimeout()
120d5b44036SJonas Devlieghere              ? m_opaque_up->GetOneThreadTimeout()->count()
121d5b44036SJonas Devlieghere              : 0;
122914f4e70SJim Ingham }
123914f4e70SJim Ingham 
124b9c1b51eSKate Stone void SBExpressionOptions::SetOneThreadTimeoutInMicroSeconds(uint32_t timeout) {
125*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions,
126*baf5664fSJonas Devlieghere                      SetOneThreadTimeoutInMicroSeconds, (uint32_t), timeout);
127*baf5664fSJonas Devlieghere 
128d5b44036SJonas Devlieghere   m_opaque_up->SetOneThreadTimeout(timeout == 0
12943d35418SPavel Labath                                        ? Timeout<std::micro>(llvm::None)
13043d35418SPavel Labath                                        : std::chrono::microseconds(timeout));
131914f4e70SJim Ingham }
132914f4e70SJim Ingham 
133b9c1b51eSKate Stone bool SBExpressionOptions::GetTryAllThreads() const {
134*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetTryAllThreads);
135*baf5664fSJonas Devlieghere 
136d5b44036SJonas Devlieghere   return m_opaque_up->GetTryAllThreads();
13735e1bda6SJim Ingham }
13835e1bda6SJim Ingham 
139b9c1b51eSKate Stone void SBExpressionOptions::SetTryAllThreads(bool run_others) {
140*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTryAllThreads, (bool),
141*baf5664fSJonas Devlieghere                      run_others);
142*baf5664fSJonas Devlieghere 
143d5b44036SJonas Devlieghere   m_opaque_up->SetTryAllThreads(run_others);
1446fbc48bcSJim Ingham }
1456fbc48bcSJim Ingham 
146b9c1b51eSKate Stone bool SBExpressionOptions::GetStopOthers() const {
147*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetStopOthers);
148*baf5664fSJonas Devlieghere 
149d5b44036SJonas Devlieghere   return m_opaque_up->GetStopOthers();
150286fb1efSJim Ingham }
151286fb1efSJim Ingham 
152b9c1b51eSKate Stone void SBExpressionOptions::SetStopOthers(bool run_others) {
153*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetStopOthers, (bool),
154*baf5664fSJonas Devlieghere                      run_others);
155*baf5664fSJonas Devlieghere 
156d5b44036SJonas Devlieghere   m_opaque_up->SetStopOthers(run_others);
157286fb1efSJim Ingham }
158286fb1efSJim Ingham 
159b9c1b51eSKate Stone bool SBExpressionOptions::GetTrapExceptions() const {
160*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
161*baf5664fSJonas Devlieghere                                    GetTrapExceptions);
162*baf5664fSJonas Devlieghere 
163d5b44036SJonas Devlieghere   return m_opaque_up->GetTrapExceptions();
1646fbc48bcSJim Ingham }
1656fbc48bcSJim Ingham 
166b9c1b51eSKate Stone void SBExpressionOptions::SetTrapExceptions(bool trap_exceptions) {
167*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTrapExceptions, (bool),
168*baf5664fSJonas Devlieghere                      trap_exceptions);
169*baf5664fSJonas Devlieghere 
170d5b44036SJonas Devlieghere   m_opaque_up->SetTrapExceptions(trap_exceptions);
17135e1bda6SJim Ingham }
17235e1bda6SJim Ingham 
173b9c1b51eSKate Stone void SBExpressionOptions::SetLanguage(lldb::LanguageType language) {
174*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetLanguage,
175*baf5664fSJonas Devlieghere                      (lldb::LanguageType), language);
176*baf5664fSJonas Devlieghere 
177d5b44036SJonas Devlieghere   m_opaque_up->SetLanguage(language);
178705b1809SJason Molenda }
179705b1809SJason Molenda 
180b9c1b51eSKate Stone void SBExpressionOptions::SetCancelCallback(
181b9c1b51eSKate Stone     lldb::ExpressionCancelCallback callback, void *baton) {
182d5b44036SJonas Devlieghere   m_opaque_up->SetCancelCallback(callback, baton);
1831624a2d3SJim Ingham }
1841624a2d3SJim Ingham 
185b9c1b51eSKate Stone bool SBExpressionOptions::GetGenerateDebugInfo() {
186*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetGenerateDebugInfo);
187*baf5664fSJonas Devlieghere 
188d5b44036SJonas Devlieghere   return m_opaque_up->GetGenerateDebugInfo();
189205ca1e8SGreg Clayton }
190205ca1e8SGreg Clayton 
191b9c1b51eSKate Stone void SBExpressionOptions::SetGenerateDebugInfo(bool b) {
192*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetGenerateDebugInfo, (bool),
193*baf5664fSJonas Devlieghere                      b);
194*baf5664fSJonas Devlieghere 
195d5b44036SJonas Devlieghere   return m_opaque_up->SetGenerateDebugInfo(b);
196205ca1e8SGreg Clayton }
197205ca1e8SGreg Clayton 
198b9c1b51eSKate Stone bool SBExpressionOptions::GetSuppressPersistentResult() {
199*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions,
200*baf5664fSJonas Devlieghere                              GetSuppressPersistentResult);
201*baf5664fSJonas Devlieghere 
202d5b44036SJonas Devlieghere   return m_opaque_up->GetResultIsInternal();
2037ab079b6SJim Ingham }
2047ab079b6SJim Ingham 
205b9c1b51eSKate Stone void SBExpressionOptions::SetSuppressPersistentResult(bool b) {
206*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetSuppressPersistentResult,
207*baf5664fSJonas Devlieghere                      (bool), b);
208*baf5664fSJonas Devlieghere 
209d5b44036SJonas Devlieghere   return m_opaque_up->SetResultIsInternal(b);
2107ab079b6SJim Ingham }
2117ab079b6SJim Ingham 
212b9c1b51eSKate Stone const char *SBExpressionOptions::GetPrefix() const {
213*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBExpressionOptions,
214*baf5664fSJonas Devlieghere                                    GetPrefix);
215*baf5664fSJonas Devlieghere 
216d5b44036SJonas Devlieghere   return m_opaque_up->GetPrefix();
2174e1042e1SGreg Clayton }
2184e1042e1SGreg Clayton 
219b9c1b51eSKate Stone void SBExpressionOptions::SetPrefix(const char *prefix) {
220*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetPrefix, (const char *),
221*baf5664fSJonas Devlieghere                      prefix);
222*baf5664fSJonas Devlieghere 
223d5b44036SJonas Devlieghere   return m_opaque_up->SetPrefix(prefix);
2244e1042e1SGreg Clayton }
2257ab079b6SJim Ingham 
226b9c1b51eSKate Stone bool SBExpressionOptions::GetAutoApplyFixIts() {
227*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetAutoApplyFixIts);
228*baf5664fSJonas Devlieghere 
229d5b44036SJonas Devlieghere   return m_opaque_up->GetAutoApplyFixIts();
230a1e541bfSJim Ingham }
231a1e541bfSJim Ingham 
232b9c1b51eSKate Stone void SBExpressionOptions::SetAutoApplyFixIts(bool b) {
233*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetAutoApplyFixIts, (bool), b);
234*baf5664fSJonas Devlieghere 
235d5b44036SJonas Devlieghere   return m_opaque_up->SetAutoApplyFixIts(b);
236a1e541bfSJim Ingham }
237a1e541bfSJim Ingham 
238b9c1b51eSKate Stone bool SBExpressionOptions::GetTopLevel() {
239*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetTopLevel);
240*baf5664fSJonas Devlieghere 
241d5b44036SJonas Devlieghere   return m_opaque_up->GetExecutionPolicy() == eExecutionPolicyTopLevel;
242863fab69SSean Callanan }
243863fab69SSean Callanan 
244b9c1b51eSKate Stone void SBExpressionOptions::SetTopLevel(bool b) {
245*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTopLevel, (bool), b);
246*baf5664fSJonas Devlieghere 
247d5b44036SJonas Devlieghere   m_opaque_up->SetExecutionPolicy(b ? eExecutionPolicyTopLevel
248d5b44036SJonas Devlieghere                                     : m_opaque_up->default_execution_policy);
249863fab69SSean Callanan }
250863fab69SSean Callanan 
251ab639986SJim Ingham bool SBExpressionOptions::GetAllowJIT() {
252*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetAllowJIT);
253*baf5664fSJonas Devlieghere 
254d5b44036SJonas Devlieghere   return m_opaque_up->GetExecutionPolicy() != eExecutionPolicyNever;
255ab639986SJim Ingham }
256ab639986SJim Ingham 
257ab639986SJim Ingham void SBExpressionOptions::SetAllowJIT(bool allow) {
258*baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetAllowJIT, (bool), allow);
259*baf5664fSJonas Devlieghere 
260d5b44036SJonas Devlieghere   m_opaque_up->SetExecutionPolicy(allow ? m_opaque_up->default_execution_policy
261ab639986SJim Ingham                                         : eExecutionPolicyNever);
262ab639986SJim Ingham }
263ab639986SJim Ingham 
264b9c1b51eSKate Stone EvaluateExpressionOptions *SBExpressionOptions::get() const {
265d5b44036SJonas Devlieghere   return m_opaque_up.get();
26635e1bda6SJim Ingham }
26735e1bda6SJim Ingham 
268b9c1b51eSKate Stone EvaluateExpressionOptions &SBExpressionOptions::ref() const {
269d5b44036SJonas Devlieghere   return *(m_opaque_up.get());
27035e1bda6SJim Ingham }
271