| 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 "Utils.h" |
| 11 | #include "lldb/API/SBStream.h" |
| 12 | #include "lldb/Target/Target.h" |
| 13 | #include "lldb/Utility/Instrumentation.h" |
| 14 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
| 18 | SBExpressionOptions::SBExpressionOptions() |
| 19 | : m_opaque_up(new EvaluateExpressionOptions()) { |
| 20 | LLDB_INSTRUMENT_VA(this); |
| 21 | } |
| 22 | |
| 23 | SBExpressionOptions::SBExpressionOptions(const SBExpressionOptions &rhs) { |
| 24 | LLDB_INSTRUMENT_VA(this, rhs); |
| 25 | |
| 26 | m_opaque_up = clone(src: rhs.m_opaque_up); |
| 27 | } |
| 28 | |
| 29 | const SBExpressionOptions &SBExpressionOptions:: |
| 30 | operator=(const SBExpressionOptions &rhs) { |
| 31 | LLDB_INSTRUMENT_VA(this, rhs); |
| 32 | |
| 33 | if (this != &rhs) |
| 34 | m_opaque_up = clone(src: rhs.m_opaque_up); |
| 35 | return *this; |
| 36 | } |
| 37 | |
| 38 | SBExpressionOptions::~SBExpressionOptions() = default; |
| 39 | |
| 40 | bool SBExpressionOptions::GetCoerceResultToId() const { |
| 41 | LLDB_INSTRUMENT_VA(this); |
| 42 | |
| 43 | return m_opaque_up->DoesCoerceToId(); |
| 44 | } |
| 45 | |
| 46 | void SBExpressionOptions::SetCoerceResultToId(bool coerce) { |
| 47 | LLDB_INSTRUMENT_VA(this, coerce); |
| 48 | |
| 49 | m_opaque_up->SetCoerceToId(coerce); |
| 50 | } |
| 51 | |
| 52 | bool SBExpressionOptions::GetUnwindOnError() const { |
| 53 | LLDB_INSTRUMENT_VA(this); |
| 54 | |
| 55 | return m_opaque_up->DoesUnwindOnError(); |
| 56 | } |
| 57 | |
| 58 | void SBExpressionOptions::SetUnwindOnError(bool unwind) { |
| 59 | LLDB_INSTRUMENT_VA(this, unwind); |
| 60 | |
| 61 | m_opaque_up->SetUnwindOnError(unwind); |
| 62 | } |
| 63 | |
| 64 | bool SBExpressionOptions::GetIgnoreBreakpoints() const { |
| 65 | LLDB_INSTRUMENT_VA(this); |
| 66 | |
| 67 | return m_opaque_up->DoesIgnoreBreakpoints(); |
| 68 | } |
| 69 | |
| 70 | void SBExpressionOptions::SetIgnoreBreakpoints(bool ignore) { |
| 71 | LLDB_INSTRUMENT_VA(this, ignore); |
| 72 | |
| 73 | m_opaque_up->SetIgnoreBreakpoints(ignore); |
| 74 | } |
| 75 | |
| 76 | lldb::DynamicValueType SBExpressionOptions::GetFetchDynamicValue() const { |
| 77 | LLDB_INSTRUMENT_VA(this); |
| 78 | |
| 79 | return m_opaque_up->GetUseDynamic(); |
| 80 | } |
| 81 | |
| 82 | void SBExpressionOptions::SetFetchDynamicValue(lldb::DynamicValueType dynamic) { |
| 83 | LLDB_INSTRUMENT_VA(this, dynamic); |
| 84 | |
| 85 | m_opaque_up->SetUseDynamic(dynamic); |
| 86 | } |
| 87 | |
| 88 | uint32_t SBExpressionOptions::GetTimeoutInMicroSeconds() const { |
| 89 | LLDB_INSTRUMENT_VA(this); |
| 90 | |
| 91 | return m_opaque_up->GetTimeout() ? m_opaque_up->GetTimeout()->count() : 0; |
| 92 | } |
| 93 | |
| 94 | void SBExpressionOptions::SetTimeoutInMicroSeconds(uint32_t timeout) { |
| 95 | LLDB_INSTRUMENT_VA(this, timeout); |
| 96 | |
| 97 | m_opaque_up->SetTimeout(timeout == 0 ? Timeout<std::micro>(std::nullopt) |
| 98 | : std::chrono::microseconds(timeout)); |
| 99 | } |
| 100 | |
| 101 | uint32_t SBExpressionOptions::GetOneThreadTimeoutInMicroSeconds() const { |
| 102 | LLDB_INSTRUMENT_VA(this); |
| 103 | |
| 104 | return m_opaque_up->GetOneThreadTimeout() |
| 105 | ? m_opaque_up->GetOneThreadTimeout()->count() |
| 106 | : 0; |
| 107 | } |
| 108 | |
| 109 | void SBExpressionOptions::SetOneThreadTimeoutInMicroSeconds(uint32_t timeout) { |
| 110 | LLDB_INSTRUMENT_VA(this, timeout); |
| 111 | |
| 112 | m_opaque_up->SetOneThreadTimeout(timeout == 0 |
| 113 | ? Timeout<std::micro>(std::nullopt) |
| 114 | : std::chrono::microseconds(timeout)); |
| 115 | } |
| 116 | |
| 117 | bool SBExpressionOptions::GetTryAllThreads() const { |
| 118 | LLDB_INSTRUMENT_VA(this); |
| 119 | |
| 120 | return m_opaque_up->GetTryAllThreads(); |
| 121 | } |
| 122 | |
| 123 | void SBExpressionOptions::SetTryAllThreads(bool run_others) { |
| 124 | LLDB_INSTRUMENT_VA(this, run_others); |
| 125 | |
| 126 | m_opaque_up->SetTryAllThreads(run_others); |
| 127 | } |
| 128 | |
| 129 | bool SBExpressionOptions::GetStopOthers() const { |
| 130 | LLDB_INSTRUMENT_VA(this); |
| 131 | |
| 132 | return m_opaque_up->GetStopOthers(); |
| 133 | } |
| 134 | |
| 135 | void SBExpressionOptions::SetStopOthers(bool run_others) { |
| 136 | LLDB_INSTRUMENT_VA(this, run_others); |
| 137 | |
| 138 | m_opaque_up->SetStopOthers(run_others); |
| 139 | } |
| 140 | |
| 141 | bool SBExpressionOptions::GetTrapExceptions() const { |
| 142 | LLDB_INSTRUMENT_VA(this); |
| 143 | |
| 144 | return m_opaque_up->GetTrapExceptions(); |
| 145 | } |
| 146 | |
| 147 | void SBExpressionOptions::SetTrapExceptions(bool trap_exceptions) { |
| 148 | LLDB_INSTRUMENT_VA(this, trap_exceptions); |
| 149 | |
| 150 | m_opaque_up->SetTrapExceptions(trap_exceptions); |
| 151 | } |
| 152 | |
| 153 | void SBExpressionOptions::SetLanguage(lldb::LanguageType language) { |
| 154 | LLDB_INSTRUMENT_VA(this, language); |
| 155 | |
| 156 | m_opaque_up->SetLanguage(language); |
| 157 | } |
| 158 | |
| 159 | void SBExpressionOptions::SetLanguage(lldb::SBSourceLanguageName name, |
| 160 | uint32_t version) { |
| 161 | LLDB_INSTRUMENT_VA(this, name, version); |
| 162 | |
| 163 | m_opaque_up->SetLanguage(name, version); |
| 164 | } |
| 165 | |
| 166 | void SBExpressionOptions::SetCancelCallback( |
| 167 | lldb::ExpressionCancelCallback callback, void *baton) { |
| 168 | LLDB_INSTRUMENT_VA(this, callback, baton); |
| 169 | |
| 170 | m_opaque_up->SetCancelCallback(callback, baton); |
| 171 | } |
| 172 | |
| 173 | bool SBExpressionOptions::GetGenerateDebugInfo() { |
| 174 | LLDB_INSTRUMENT_VA(this); |
| 175 | |
| 176 | return m_opaque_up->GetGenerateDebugInfo(); |
| 177 | } |
| 178 | |
| 179 | void SBExpressionOptions::SetGenerateDebugInfo(bool b) { |
| 180 | LLDB_INSTRUMENT_VA(this, b); |
| 181 | |
| 182 | return m_opaque_up->SetGenerateDebugInfo(b); |
| 183 | } |
| 184 | |
| 185 | bool SBExpressionOptions::GetSuppressPersistentResult() { |
| 186 | LLDB_INSTRUMENT_VA(this); |
| 187 | |
| 188 | return m_opaque_up->GetSuppressPersistentResult(); |
| 189 | } |
| 190 | |
| 191 | void SBExpressionOptions::SetSuppressPersistentResult(bool b) { |
| 192 | LLDB_INSTRUMENT_VA(this, b); |
| 193 | |
| 194 | return m_opaque_up->SetSuppressPersistentResult(b); |
| 195 | } |
| 196 | |
| 197 | const char *SBExpressionOptions::GetPrefix() const { |
| 198 | LLDB_INSTRUMENT_VA(this); |
| 199 | |
| 200 | return ConstString(m_opaque_up->GetPrefix()).GetCString(); |
| 201 | } |
| 202 | |
| 203 | void SBExpressionOptions::SetPrefix(const char *prefix) { |
| 204 | LLDB_INSTRUMENT_VA(this, prefix); |
| 205 | |
| 206 | return m_opaque_up->SetPrefix(prefix); |
| 207 | } |
| 208 | |
| 209 | bool SBExpressionOptions::GetAutoApplyFixIts() { |
| 210 | LLDB_INSTRUMENT_VA(this); |
| 211 | |
| 212 | return m_opaque_up->GetAutoApplyFixIts(); |
| 213 | } |
| 214 | |
| 215 | void SBExpressionOptions::SetAutoApplyFixIts(bool b) { |
| 216 | LLDB_INSTRUMENT_VA(this, b); |
| 217 | |
| 218 | return m_opaque_up->SetAutoApplyFixIts(b); |
| 219 | } |
| 220 | |
| 221 | uint64_t SBExpressionOptions::GetRetriesWithFixIts() { |
| 222 | LLDB_INSTRUMENT_VA(this); |
| 223 | |
| 224 | return m_opaque_up->GetRetriesWithFixIts(); |
| 225 | } |
| 226 | |
| 227 | void SBExpressionOptions::SetRetriesWithFixIts(uint64_t retries) { |
| 228 | LLDB_INSTRUMENT_VA(this, retries); |
| 229 | |
| 230 | return m_opaque_up->SetRetriesWithFixIts(retries); |
| 231 | } |
| 232 | |
| 233 | bool SBExpressionOptions::GetTopLevel() { |
| 234 | LLDB_INSTRUMENT_VA(this); |
| 235 | |
| 236 | return m_opaque_up->GetExecutionPolicy() == eExecutionPolicyTopLevel; |
| 237 | } |
| 238 | |
| 239 | void SBExpressionOptions::SetTopLevel(bool b) { |
| 240 | LLDB_INSTRUMENT_VA(this, b); |
| 241 | |
| 242 | m_opaque_up->SetExecutionPolicy(b ? eExecutionPolicyTopLevel |
| 243 | : m_opaque_up->default_execution_policy); |
| 244 | } |
| 245 | |
| 246 | bool SBExpressionOptions::GetAllowJIT() { |
| 247 | LLDB_INSTRUMENT_VA(this); |
| 248 | |
| 249 | return m_opaque_up->GetExecutionPolicy() != eExecutionPolicyNever; |
| 250 | } |
| 251 | |
| 252 | void SBExpressionOptions::SetAllowJIT(bool allow) { |
| 253 | LLDB_INSTRUMENT_VA(this, allow); |
| 254 | |
| 255 | m_opaque_up->SetExecutionPolicy(allow ? m_opaque_up->default_execution_policy |
| 256 | : eExecutionPolicyNever); |
| 257 | } |
| 258 | |
| 259 | EvaluateExpressionOptions *SBExpressionOptions::get() const { |
| 260 | return m_opaque_up.get(); |
| 261 | } |
| 262 | |
| 263 | EvaluateExpressionOptions &SBExpressionOptions::ref() const { |
| 264 | return *m_opaque_up; |
| 265 | } |
| 266 | |