1 //===-- OptionValueUInt64.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/OptionValueUInt64.h"
10
11 #include "lldb/Host/StringConvert.h"
12 #include "lldb/Utility/Stream.h"
13
14 using namespace lldb;
15 using namespace lldb_private;
16
Create(llvm::StringRef value_str,Status & error)17 lldb::OptionValueSP OptionValueUInt64::Create(llvm::StringRef value_str,
18 Status &error) {
19 lldb::OptionValueSP value_sp(new OptionValueUInt64());
20 error = value_sp->SetValueFromString(value_str);
21 if (error.Fail())
22 value_sp.reset();
23 return value_sp;
24 }
25
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)26 void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
27 uint32_t dump_mask) {
28 if (dump_mask & eDumpOptionType)
29 strm.Printf("(%s)", GetTypeAsCString());
30 if (dump_mask & eDumpOptionValue) {
31 if (dump_mask & eDumpOptionType)
32 strm.PutCString(" = ");
33 strm.Printf("%" PRIu64, m_current_value);
34 }
35 }
36
SetValueFromString(llvm::StringRef value_ref,VarSetOperationType op)37 Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,
38 VarSetOperationType op) {
39 Status error;
40 switch (op) {
41 case eVarSetOperationClear:
42 Clear();
43 NotifyValueChanged();
44 break;
45
46 case eVarSetOperationReplace:
47 case eVarSetOperationAssign: {
48 bool success = false;
49 std::string value_str = value_ref.trim().str();
50 uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success);
51 if (success) {
52 m_value_was_set = true;
53 m_current_value = value;
54 NotifyValueChanged();
55 } else {
56 error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
57 value_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_ref, op);
67 break;
68 }
69 return error;
70 }
71