Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1 | //===-- OptionValueSInt64.cpp -----------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Interpreter/OptionValueSInt64.h" |
| 10 | |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame] | 11 | #include "lldb/Host/StringConvert.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 12 | #include "lldb/Utility/Stream.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 17 | void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 18 | uint32_t dump_mask) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 19 | // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %" |
| 20 | // PRIi64 |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | // "\n", this, exe_ctx, m_current_value); |
| 22 | if (dump_mask & eDumpOptionType) |
| 23 | strm.Printf("(%s)", GetTypeAsCString()); |
| 24 | // if (dump_mask & eDumpOptionName) |
| 25 | // DumpQualifiedName (strm); |
| 26 | if (dump_mask & eDumpOptionValue) { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 27 | if (dump_mask & eDumpOptionType) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | strm.PutCString(" = "); |
| 29 | strm.Printf("%" PRIi64, m_current_value); |
| 30 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 33 | Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref, |
| 34 | VarSetOperationType op) { |
| 35 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 36 | switch (op) { |
| 37 | case eVarSetOperationClear: |
| 38 | Clear(); |
| 39 | NotifyValueChanged(); |
| 40 | break; |
| 41 | |
| 42 | case eVarSetOperationReplace: |
| 43 | case eVarSetOperationAssign: { |
| 44 | bool success = false; |
| 45 | std::string value_str = value_ref.trim().str(); |
| 46 | int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success); |
| 47 | if (success) { |
| 48 | if (value >= m_min_value && value <= m_max_value) { |
| 49 | m_value_was_set = true; |
| 50 | m_current_value = value; |
| 51 | NotifyValueChanged(); |
| 52 | } else |
| 53 | error.SetErrorStringWithFormat( |
| 54 | "%" PRIi64 " is out of range, valid values must be between %" PRIi64 |
| 55 | " and %" PRIi64 ".", |
| 56 | value, m_min_value, m_max_value); |
| 57 | } else { |
| 58 | error.SetErrorStringWithFormat("invalid int64_t string value: '%s'", |
| 59 | value_ref.str().c_str()); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 60 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | } break; |
| 62 | |
| 63 | case eVarSetOperationInsertBefore: |
| 64 | case eVarSetOperationInsertAfter: |
| 65 | case eVarSetOperationRemove: |
| 66 | case eVarSetOperationAppend: |
| 67 | case eVarSetOperationInvalid: |
| 68 | error = OptionValue::SetValueFromString(value_ref, op); |
| 69 | break; |
| 70 | } |
| 71 | return error; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | lldb::OptionValueSP OptionValueSInt64::DeepCopy() const { |
| 75 | return OptionValueSP(new OptionValueSInt64(*this)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 76 | } |