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/Host/StringConvert.h"
17 #include "lldb/Utility/Stream.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
22 void OptionValueSInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
23                                   uint32_t dump_mask) {
24   // printf ("%p: DumpValue (exe_ctx=%p, strm, mask) m_current_value = %"
25   // PRIi64
26   // "\n", this, exe_ctx, m_current_value);
27   if (dump_mask & eDumpOptionType)
28     strm.Printf("(%s)", GetTypeAsCString());
29   //    if (dump_mask & eDumpOptionName)
30   //        DumpQualifiedName (strm);
31   if (dump_mask & eDumpOptionValue) {
32     if (dump_mask & eDumpOptionType)
33       strm.PutCString(" = ");
34     strm.Printf("%" PRIi64, m_current_value);
35   }
36 }
37 
38 Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref,
39                                              VarSetOperationType op) {
40   Status error;
41   switch (op) {
42   case eVarSetOperationClear:
43     Clear();
44     NotifyValueChanged();
45     break;
46 
47   case eVarSetOperationReplace:
48   case eVarSetOperationAssign: {
49     bool success = false;
50     std::string value_str = value_ref.trim().str();
51     int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success);
52     if (success) {
53       if (value >= m_min_value && value <= m_max_value) {
54         m_value_was_set = true;
55         m_current_value = value;
56         NotifyValueChanged();
57       } else
58         error.SetErrorStringWithFormat(
59             "%" PRIi64 " is out of range, valid values must be between %" PRIi64
60             " and %" PRIi64 ".",
61             value, m_min_value, m_max_value);
62     } else {
63       error.SetErrorStringWithFormat("invalid int64_t string value: '%s'",
64                                      value_ref.str().c_str());
65     }
66   } break;
67 
68   case eVarSetOperationInsertBefore:
69   case eVarSetOperationInsertAfter:
70   case eVarSetOperationRemove:
71   case eVarSetOperationAppend:
72   case eVarSetOperationInvalid:
73     error = OptionValue::SetValueFromString(value_ref, op);
74     break;
75   }
76   return error;
77 }
78 
79 lldb::OptionValueSP OptionValueSInt64::DeepCopy() const {
80   return OptionValueSP(new OptionValueSInt64(*this));
81 }
82