LLDB  mainline
OptionValueUInt64.cpp
Go to the documentation of this file.
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 
10 
12 #include "lldb/Utility/Stream.h"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
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 
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 
37 Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref,
39  Status error;
40  switch (op) {
42  Clear();
43  NotifyValueChanged();
44  break;
45 
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 
66  error = OptionValue::SetValueFromString(value_ref, op);
67  break;
68  }
69  return error;
70 }
71 
72 lldb::OptionValueSP OptionValueUInt64::DeepCopy() const {
73  return OptionValueSP(new OptionValueUInt64(*this));
74 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
A class that represents a running process on the host machine.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
VarSetOperationType
Settable state variable types.
static llvm::raw_ostream & error(Stream &strm)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
Definition: SBAddress.h:15
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:256
uint64_t ToUInt64(const char *s, uint64_t fail_value=0, int base=0, bool *success_ptr=nullptr)
static bool DumpValue(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const FormatEntity::Entry &entry, ValueObject *valobj)
An error handling class.
Definition: Status.h:44