Path: blob/main/contrib/llvm-project/lldb/source/Interpreter/OptionValueUInt64.cpp
39587 views
//===-- OptionValueUInt64.cpp ---------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Interpreter/OptionValueUInt64.h"910#include "lldb/Utility/Stream.h"1112using namespace lldb;13using namespace lldb_private;1415lldb::OptionValueSP OptionValueUInt64::Create(llvm::StringRef value_str,16Status &error) {17lldb::OptionValueSP value_sp(new OptionValueUInt64());18error = value_sp->SetValueFromString(value_str);19if (error.Fail())20value_sp.reset();21return value_sp;22}2324void OptionValueUInt64::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,25uint32_t dump_mask) {26if (dump_mask & eDumpOptionType)27strm.Printf("(%s)", GetTypeAsCString());28if (dump_mask & eDumpOptionValue) {29if (dump_mask & eDumpOptionType)30strm.PutCString(" = ");31strm.Printf("%" PRIu64, m_current_value);32}33}3435Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,36VarSetOperationType op) {37Status error;38switch (op) {39case eVarSetOperationClear:40Clear();41NotifyValueChanged();42break;4344case eVarSetOperationReplace:45case eVarSetOperationAssign: {46llvm::StringRef value_trimmed = value_ref.trim();47uint64_t value;48if (llvm::to_integer(value_trimmed, value)) {49if (value >= m_min_value && value <= m_max_value) {50m_value_was_set = true;51m_current_value = value;52NotifyValueChanged();53} else {54error.SetErrorStringWithFormat(55"%" PRIu64 " is out of range, valid values must be between %" PRIu6456" and %" PRIu64 ".",57value, m_min_value, m_max_value);58}59} else {60error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",61value_ref.str().c_str());62}63} break;6465case eVarSetOperationInsertBefore:66case eVarSetOperationInsertAfter:67case eVarSetOperationRemove:68case eVarSetOperationAppend:69case eVarSetOperationInvalid:70error = OptionValue::SetValueFromString(value_ref, op);71break;72}73return error;74}757677