| 1 | //===-- OptionValueSInt64.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/Interpreter/OptionValueSInt64.h" |
| 10 | |
| 11 | #include "lldb/Utility/Stream.h" |
| 12 | |
| 13 | using namespace lldb; |
| 14 | using namespace lldb_private; |
| 15 | |
| 16 | void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 17 | uint32_t dump_mask) { |
| 18 | // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %" |
| 19 | // PRIi64 |
| 20 | // "\n", this, exe_ctx, m_current_value); |
| 21 | if (dump_mask & eDumpOptionType) |
| 22 | strm.Printf(format: "(%s)" , GetTypeAsCString()); |
| 23 | // if (dump_mask & eDumpOptionName) |
| 24 | // DumpQualifiedName (strm); |
| 25 | if (dump_mask & eDumpOptionValue) { |
| 26 | if (dump_mask & eDumpOptionType) |
| 27 | strm.PutCString(cstr: " = " ); |
| 28 | strm.Printf(format: "%" PRIi64, m_current_value); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref, |
| 33 | VarSetOperationType op) { |
| 34 | Status error; |
| 35 | switch (op) { |
| 36 | case eVarSetOperationClear: |
| 37 | Clear(); |
| 38 | NotifyValueChanged(); |
| 39 | break; |
| 40 | |
| 41 | case eVarSetOperationReplace: |
| 42 | case eVarSetOperationAssign: { |
| 43 | llvm::StringRef value_trimmed = value_ref.trim(); |
| 44 | int64_t value; |
| 45 | if (llvm::to_integer(S: value_trimmed, Num&: value)) { |
| 46 | if (value >= m_min_value && value <= m_max_value) { |
| 47 | m_value_was_set = true; |
| 48 | m_current_value = value; |
| 49 | NotifyValueChanged(); |
| 50 | } else |
| 51 | error = Status::FromErrorStringWithFormat( |
| 52 | format: "%" PRIi64 " is out of range, valid values must be between %" PRIi64 |
| 53 | " and %" PRIi64 "." , |
| 54 | value, m_min_value, m_max_value); |
| 55 | } else { |
| 56 | error = Status::FromErrorStringWithFormat( |
| 57 | format: "invalid int64_t string value: '%s'" , value_ref.str().c_str()); |
| 58 | } |
| 59 | } break; |
| 60 | |
| 61 | case eVarSetOperationInsertBefore: |
| 62 | case eVarSetOperationInsertAfter: |
| 63 | case eVarSetOperationRemove: |
| 64 | case eVarSetOperationAppend: |
| 65 | case eVarSetOperationInvalid: |
| 66 | error = OptionValue::SetValueFromString(value: value_ref, op); |
| 67 | break; |
| 68 | } |
| 69 | return error; |
| 70 | } |
| 71 | |