1 //===-- OptionValueSInt64.cpp -----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionValueSInt64.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Stream.h" 17 #include "lldb/Host/StringConvert.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 void 23 OptionValueSInt64::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 24 { 25 //printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %" PRIi64 "\n", this, exe_ctx, m_current_value); 26 if (dump_mask & eDumpOptionType) 27 strm.Printf ("(%s)", GetTypeAsCString ()); 28 // if (dump_mask & eDumpOptionName) 29 // DumpQualifiedName (strm); 30 if (dump_mask & eDumpOptionValue) 31 { 32 if (dump_mask & eDumpOptionType) 33 strm.PutCString (" = "); 34 strm.Printf ("%" PRIi64, m_current_value); 35 } 36 } 37 38 Error 39 OptionValueSInt64::SetValueFromCString (const char *value_cstr, VarSetOperationType op) 40 { 41 //printf ("%p: SetValueFromCString (s=\"%s\", op=%i)\n", this, value_cstr, op); 42 Error error; 43 switch (op) 44 { 45 case eVarSetOperationClear: 46 Clear(); 47 NotifyValueChanged(); 48 break; 49 50 case eVarSetOperationReplace: 51 case eVarSetOperationAssign: 52 { 53 bool success = false; 54 std::string value_str = llvm::StringRef(value_cstr).trim().str(); 55 int64_t value = StringConvert::ToSInt64 (value_str.c_str(), 0, 0, &success); 56 if (success) 57 { 58 if (value >= m_min_value && value <= m_max_value) 59 { 60 m_value_was_set = true; 61 m_current_value = value; 62 NotifyValueChanged(); 63 } 64 else 65 error.SetErrorStringWithFormat ("%" PRIi64 " is out of range, valid values must be between %" PRIi64 " and %" PRIi64 ".", 66 value, 67 m_min_value, 68 m_max_value); 69 } 70 else 71 { 72 error.SetErrorStringWithFormat ("invalid int64_t string value: '%s'", value_cstr); 73 } 74 } 75 break; 76 77 case eVarSetOperationInsertBefore: 78 case eVarSetOperationInsertAfter: 79 case eVarSetOperationRemove: 80 case eVarSetOperationAppend: 81 case eVarSetOperationInvalid: 82 error = OptionValue::SetValueFromCString (value_cstr, op); 83 break; 84 } 85 return error; 86 } 87 88 lldb::OptionValueSP 89 OptionValueSInt64::DeepCopy () const 90 { 91 return OptionValueSP(new OptionValueSInt64(*this)); 92 } 93