LLDB  mainline
OptionValueUUID.cpp
Go to the documentation of this file.
1 //===-- OptionValueUUID.cpp ------------------------------------*- C++ -*-===//
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 
11 #include "lldb/Core/Module.h"
13 #include "lldb/Utility/Stream.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
20  uint32_t dump_mask) {
21  if (dump_mask & eDumpOptionType)
22  strm.Printf("(%s)", GetTypeAsCString());
23  if (dump_mask & eDumpOptionValue) {
24  if (dump_mask & eDumpOptionType)
25  strm.PutCString(" = ");
26  m_uuid.Dump(&strm);
27  }
28 }
29 
30 Status OptionValueUUID::SetValueFromString(llvm::StringRef value,
32  Status error;
33  switch (op) {
35  Clear();
36  NotifyValueChanged();
37  break;
38 
41  if (m_uuid.SetFromStringRef(value) == 0)
42  error.SetErrorStringWithFormat("invalid uuid string value '%s'",
43  value.str().c_str());
44  else {
45  m_value_was_set = true;
46  NotifyValueChanged();
47  }
48  } break;
49 
55  error = OptionValue::SetValueFromString(value, op);
56  break;
57  }
58  return error;
59 }
60 
61 lldb::OptionValueSP OptionValueUUID::DeepCopy() const {
62  return OptionValueSP(new OptionValueUUID(*this));
63 }
64 
65 size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
66  CompletionRequest &request) {
67  request.SetWordComplete(false);
68  ExecutionContext exe_ctx(interpreter.GetExecutionContext());
69  Target *target = exe_ctx.GetTargetPtr();
70  if (target) {
71  auto prefix = request.GetCursorArgumentPrefix();
72  llvm::SmallVector<uint8_t, 20> uuid_bytes;
73  if (UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty()) {
74  const size_t num_modules = target->GetImages().GetSize();
75  for (size_t i = 0; i < num_modules; ++i) {
76  ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
77  if (module_sp) {
78  const UUID &module_uuid = module_sp->GetUUID();
79  if (module_uuid.IsValid()) {
80  llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes();
81  if (module_bytes.size() >= uuid_bytes.size() &&
82  module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) {
83  request.AddCompletion(module_uuid.GetAsString());
84  }
85  }
86  }
87  }
88  }
89  }
90  return request.GetNumberOfMatches();
91 }
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
bool IsValid() const
Definition: UUID.h:65
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
std::size_t GetNumberOfMatches() const
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string.
"lldb/Utility/ArgCompletionRequest.h"
std::string GetAsString(llvm::StringRef separator="-") const
Definition: UUID.cpp:38
llvm::StringRef GetCursorArgumentPrefix() const
VarSetOperationType
Settable state variable types.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:106
llvm::ArrayRef< uint8_t > GetBytes() const
Definition: UUID.h:62
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:255
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