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"
11baf5664fSJonas 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()
20baf5664fSJonas Devlieghere     : m_opaque_up(new EvaluateExpressionOptions()) {
21baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBExpressionOptions);
22baf5664fSJonas Devlieghere }
2335e1bda6SJim Ingham 
24bd4bf82aSJonas Devlieghere SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs)
25bd4bf82aSJonas Devlieghere     : m_opaque_up() {
26baf5664fSJonas Devlieghere   LLDB_RECORD_CONSTRUCTOR(SBExpressionOptions,
27baf5664fSJonas Devlieghere                           (const lldb::SBExpressionOptions &), rhs);
28baf5664fSJonas 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) {
34baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(
35baf5664fSJonas Devlieghere       const lldb::SBExpressionOptions &,
36baf5664fSJonas Devlieghere       SBExpressionOptions, operator=,(const lldb::SBExpressionOptions &), rhs);
37baf5664fSJonas 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 {
46baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
47baf5664fSJonas Devlieghere                                    GetCoerceResultToId);
48baf5664fSJonas Devlieghere 
49d5b44036SJonas Devlieghere   return m_opaque_up->DoesCoerceToId();
5035e1bda6SJim Ingham }
5135e1bda6SJim Ingham 
52b9c1b51eSKate Stone void SBExpressionOptions::SetCoerceResultToId(bool coerce) {
53baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetCoerceResultToId, (bool),
54baf5664fSJonas Devlieghere                      coerce);
55baf5664fSJonas Devlieghere 
56d5b44036SJonas Devlieghere   m_opaque_up->SetCoerceToId(coerce);
5735e1bda6SJim Ingham }
5835e1bda6SJim Ingham 
59b9c1b51eSKate Stone bool SBExpressionOptions::GetUnwindOnError() const {
60baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetUnwindOnError);
61baf5664fSJonas Devlieghere 
62d5b44036SJonas Devlieghere   return m_opaque_up->DoesUnwindOnError();
6335e1bda6SJim Ingham }
6435e1bda6SJim Ingham 
65b9c1b51eSKate Stone void SBExpressionOptions::SetUnwindOnError(bool unwind) {
66baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetUnwindOnError, (bool),
67baf5664fSJonas Devlieghere                      unwind);
68baf5664fSJonas Devlieghere 
69d5b44036SJonas Devlieghere   m_opaque_up->SetUnwindOnError(unwind);
7035e1bda6SJim Ingham }
7135e1bda6SJim Ingham 
72b9c1b51eSKate Stone bool SBExpressionOptions::GetIgnoreBreakpoints() const {
73baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
74baf5664fSJonas Devlieghere                                    GetIgnoreBreakpoints);
75baf5664fSJonas Devlieghere 
76d5b44036SJonas Devlieghere   return m_opaque_up->DoesIgnoreBreakpoints();
77184e9811SJim Ingham }
78184e9811SJim Ingham 
79b9c1b51eSKate Stone void SBExpressionOptions::SetIgnoreBreakpoints(bool ignore) {
80baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetIgnoreBreakpoints, (bool),
81baf5664fSJonas Devlieghere                      ignore);
82baf5664fSJonas Devlieghere 
83d5b44036SJonas Devlieghere   m_opaque_up->SetIgnoreBreakpoints(ignore);
84184e9811SJim Ingham }
85184e9811SJim Ingham 
86b9c1b51eSKate Stone lldb::DynamicValueType SBExpressionOptions::GetFetchDynamicValue() const {
87baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::DynamicValueType, SBExpressionOptions,
88baf5664fSJonas Devlieghere                                    GetFetchDynamicValue);
89baf5664fSJonas Devlieghere 
90d5b44036SJonas Devlieghere   return m_opaque_up->GetUseDynamic();
9135e1bda6SJim Ingham }
9235e1bda6SJim Ingham 
93b9c1b51eSKate Stone void SBExpressionOptions::SetFetchDynamicValue(lldb::DynamicValueType dynamic) {
94baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetFetchDynamicValue,
95baf5664fSJonas Devlieghere                      (lldb::DynamicValueType), dynamic);
96baf5664fSJonas Devlieghere 
97d5b44036SJonas Devlieghere   m_opaque_up->SetUseDynamic(dynamic);
9835e1bda6SJim Ingham }
9935e1bda6SJim Ingham 
100b9c1b51eSKate Stone uint32_t SBExpressionOptions::GetTimeoutInMicroSeconds() const {
101baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBExpressionOptions,
102baf5664fSJonas Devlieghere                                    GetTimeoutInMicroSeconds);
103baf5664fSJonas 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) {
108baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTimeoutInMicroSeconds,
109baf5664fSJonas Devlieghere                      (uint32_t), timeout);
110baf5664fSJonas 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 {
116baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBExpressionOptions,
117baf5664fSJonas Devlieghere                                    GetOneThreadTimeoutInMicroSeconds);
118baf5664fSJonas 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) {
125baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions,
126baf5664fSJonas Devlieghere                      SetOneThreadTimeoutInMicroSeconds, (uint32_t), timeout);
127baf5664fSJonas 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 {
134baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetTryAllThreads);
135baf5664fSJonas Devlieghere 
136d5b44036SJonas Devlieghere   return m_opaque_up->GetTryAllThreads();
13735e1bda6SJim Ingham }
13835e1bda6SJim Ingham 
139b9c1b51eSKate Stone void SBExpressionOptions::SetTryAllThreads(bool run_others) {
140baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTryAllThreads, (bool),
141baf5664fSJonas Devlieghere                      run_others);
142baf5664fSJonas Devlieghere 
143d5b44036SJonas Devlieghere   m_opaque_up->SetTryAllThreads(run_others);
1446fbc48bcSJim Ingham }
1456fbc48bcSJim Ingham 
146b9c1b51eSKate Stone bool SBExpressionOptions::GetStopOthers() const {
147baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions, GetStopOthers);
148baf5664fSJonas Devlieghere 
149d5b44036SJonas Devlieghere   return m_opaque_up->GetStopOthers();
150286fb1efSJim Ingham }
151286fb1efSJim Ingham 
152b9c1b51eSKate Stone void SBExpressionOptions::SetStopOthers(bool run_others) {
153baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetStopOthers, (bool),
154baf5664fSJonas Devlieghere                      run_others);
155baf5664fSJonas Devlieghere 
156d5b44036SJonas Devlieghere   m_opaque_up->SetStopOthers(run_others);
157286fb1efSJim Ingham }
158286fb1efSJim Ingham 
159b9c1b51eSKate Stone bool SBExpressionOptions::GetTrapExceptions() const {
160baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBExpressionOptions,
161baf5664fSJonas Devlieghere                                    GetTrapExceptions);
162baf5664fSJonas Devlieghere 
163d5b44036SJonas Devlieghere   return m_opaque_up->GetTrapExceptions();
1646fbc48bcSJim Ingham }
1656fbc48bcSJim Ingham 
166b9c1b51eSKate Stone void SBExpressionOptions::SetTrapExceptions(bool trap_exceptions) {
167baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTrapExceptions, (bool),
168baf5664fSJonas Devlieghere                      trap_exceptions);
169baf5664fSJonas Devlieghere 
170d5b44036SJonas Devlieghere   m_opaque_up->SetTrapExceptions(trap_exceptions);
17135e1bda6SJim Ingham }
17235e1bda6SJim Ingham 
173b9c1b51eSKate Stone void SBExpressionOptions::SetLanguage(lldb::LanguageType language) {
174baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetLanguage,
175baf5664fSJonas Devlieghere                      (lldb::LanguageType), language);
176baf5664fSJonas Devlieghere 
177d5b44036SJonas Devlieghere   m_opaque_up->SetLanguage(language);
178705b1809SJason Molenda }
179705b1809SJason Molenda 
180b9c1b51eSKate Stone void SBExpressionOptions::SetCancelCallback(
181b9c1b51eSKate Stone     lldb::ExpressionCancelCallback callback, void *baton) {
1820d7b0c96SJonas Devlieghere   LLDB_RECORD_DUMMY(void, SBExpressionOptions, SetCancelCallback,
183*7bc83564SJonas Devlieghere                     (lldb::ExpressionCancelCallback, void *), callback, baton);
1840d7b0c96SJonas Devlieghere 
185d5b44036SJonas Devlieghere   m_opaque_up->SetCancelCallback(callback, baton);
1861624a2d3SJim Ingham }
1871624a2d3SJim Ingham 
188b9c1b51eSKate Stone bool SBExpressionOptions::GetGenerateDebugInfo() {
189baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetGenerateDebugInfo);
190baf5664fSJonas Devlieghere 
191d5b44036SJonas Devlieghere   return m_opaque_up->GetGenerateDebugInfo();
192205ca1e8SGreg Clayton }
193205ca1e8SGreg Clayton 
194b9c1b51eSKate Stone void SBExpressionOptions::SetGenerateDebugInfo(bool b) {
195baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetGenerateDebugInfo, (bool),
196baf5664fSJonas Devlieghere                      b);
197baf5664fSJonas Devlieghere 
198d5b44036SJonas Devlieghere   return m_opaque_up->SetGenerateDebugInfo(b);
199205ca1e8SGreg Clayton }
200205ca1e8SGreg Clayton 
201b9c1b51eSKate Stone bool SBExpressionOptions::GetSuppressPersistentResult() {
202baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions,
203baf5664fSJonas Devlieghere                              GetSuppressPersistentResult);
204baf5664fSJonas Devlieghere 
205d5b44036SJonas Devlieghere   return m_opaque_up->GetResultIsInternal();
2067ab079b6SJim Ingham }
2077ab079b6SJim Ingham 
208b9c1b51eSKate Stone void SBExpressionOptions::SetSuppressPersistentResult(bool b) {
209baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetSuppressPersistentResult,
210baf5664fSJonas Devlieghere                      (bool), b);
211baf5664fSJonas Devlieghere 
212d5b44036SJonas Devlieghere   return m_opaque_up->SetResultIsInternal(b);
2137ab079b6SJim Ingham }
2147ab079b6SJim Ingham 
215b9c1b51eSKate Stone const char *SBExpressionOptions::GetPrefix() const {
216baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBExpressionOptions,
217baf5664fSJonas Devlieghere                                    GetPrefix);
218baf5664fSJonas Devlieghere 
219d5b44036SJonas Devlieghere   return m_opaque_up->GetPrefix();
2204e1042e1SGreg Clayton }
2214e1042e1SGreg Clayton 
222b9c1b51eSKate Stone void SBExpressionOptions::SetPrefix(const char *prefix) {
223baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetPrefix, (const char *),
224baf5664fSJonas Devlieghere                      prefix);
225baf5664fSJonas Devlieghere 
226d5b44036SJonas Devlieghere   return m_opaque_up->SetPrefix(prefix);
2274e1042e1SGreg Clayton }
2287ab079b6SJim Ingham 
229b9c1b51eSKate Stone bool SBExpressionOptions::GetAutoApplyFixIts() {
230baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetAutoApplyFixIts);
231baf5664fSJonas Devlieghere 
232d5b44036SJonas Devlieghere   return m_opaque_up->GetAutoApplyFixIts();
233a1e541bfSJim Ingham }
234a1e541bfSJim Ingham 
235b9c1b51eSKate Stone void SBExpressionOptions::SetAutoApplyFixIts(bool b) {
236baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetAutoApplyFixIts, (bool), b);
237baf5664fSJonas Devlieghere 
238d5b44036SJonas Devlieghere   return m_opaque_up->SetAutoApplyFixIts(b);
239a1e541bfSJim Ingham }
240a1e541bfSJim Ingham 
241b9c1b51eSKate Stone bool SBExpressionOptions::GetTopLevel() {
242baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetTopLevel);
243baf5664fSJonas Devlieghere 
244d5b44036SJonas Devlieghere   return m_opaque_up->GetExecutionPolicy() == eExecutionPolicyTopLevel;
245863fab69SSean Callanan }
246863fab69SSean Callanan 
247b9c1b51eSKate Stone void SBExpressionOptions::SetTopLevel(bool b) {
248baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetTopLevel, (bool), b);
249baf5664fSJonas Devlieghere 
250d5b44036SJonas Devlieghere   m_opaque_up->SetExecutionPolicy(b ? eExecutionPolicyTopLevel
251d5b44036SJonas Devlieghere                                     : m_opaque_up->default_execution_policy);
252863fab69SSean Callanan }
253863fab69SSean Callanan 
254ab639986SJim Ingham bool SBExpressionOptions::GetAllowJIT() {
255baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD_NO_ARGS(bool, SBExpressionOptions, GetAllowJIT);
256baf5664fSJonas Devlieghere 
257d5b44036SJonas Devlieghere   return m_opaque_up->GetExecutionPolicy() != eExecutionPolicyNever;
258ab639986SJim Ingham }
259ab639986SJim Ingham 
260ab639986SJim Ingham void SBExpressionOptions::SetAllowJIT(bool allow) {
261baf5664fSJonas Devlieghere   LLDB_RECORD_METHOD(void, SBExpressionOptions, SetAllowJIT, (bool), allow);
262baf5664fSJonas Devlieghere 
263d5b44036SJonas Devlieghere   m_opaque_up->SetExecutionPolicy(allow ? m_opaque_up->default_execution_policy
264ab639986SJim Ingham                                         : eExecutionPolicyNever);
265ab639986SJim Ingham }
266ab639986SJim Ingham 
267b9c1b51eSKate Stone EvaluateExpressionOptions *SBExpressionOptions::get() const {
268d5b44036SJonas Devlieghere   return m_opaque_up.get();
26935e1bda6SJim Ingham }
27035e1bda6SJim Ingham 
271b9c1b51eSKate Stone EvaluateExpressionOptions &SBExpressionOptions::ref() const {
272d5b44036SJonas Devlieghere   return *(m_opaque_up.get());
27335e1bda6SJim Ingham }
274