LLDB  mainline
OptionValueUUID.cpp
Go to the documentation of this file.
1 //===-- OptionValueUUID.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 
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))
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 void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
62  CompletionRequest &request) {
63  ExecutionContext exe_ctx(interpreter.GetExecutionContext());
64  Target *target = exe_ctx.GetTargetPtr();
65  if (!target)
66  return;
67  auto prefix = request.GetCursorArgumentPrefix();
68  llvm::SmallVector<uint8_t, 20> uuid_bytes;
69  if (!UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty())
70  return;
71  const size_t num_modules = target->GetImages().GetSize();
72  for (size_t i = 0; i < num_modules; ++i) {
73  ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
74  if (!module_sp)
75  continue;
76  const UUID &module_uuid = module_sp->GetUUID();
77  if (!module_uuid.IsValid())
78  continue;
79  request.TryCompleteCurrentArg(module_uuid.GetAsString());
80  }
81 }
lldb_private::eVarSetOperationInsertBefore
@ eVarSetOperationInsertBefore
Definition: lldb-private-enumerations.h:85
lldb_private::UUID
Definition: UUID.h:23
lldb_private::eVarSetOperationReplace
@ eVarSetOperationReplace
Definition: lldb-private-enumerations.h:84
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
OptionValueUUID.h
lldb_private::CompletionRequest::TryCompleteCurrentArg
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
Definition: CompletionRequest.h:180
lldb_private::UUID::IsValid
bool IsValid() const
Definition: UUID.h:79
Module.h
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Target
Definition: Target.h:451
lldb_private::Target::GetImages
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:925
lldb_private::UUID::GetAsString
std::string GetAsString(llvm::StringRef separator="-") const
Definition: UUID.cpp:48
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::VarSetOperationType
VarSetOperationType
Settable state variable types.
Definition: lldb-private-enumerations.h:83
lldb_private::ModuleList::GetSize
size_t GetSize() const
Gets the size of the module list.
Definition: ModuleList.cpp:594
lldb_private::eVarSetOperationAppend
@ eVarSetOperationAppend
Definition: lldb-private-enumerations.h:88
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::CompletionRequest::GetCursorArgumentPrefix
llvm::StringRef GetCursorArgumentPrefix() const
Definition: CompletionRequest.h:217
StringList.h
lldb_private::Status
Definition: Status.h:44
uint32_t
lldb_private::eVarSetOperationRemove
@ eVarSetOperationRemove
Definition: lldb-private-enumerations.h:87
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ModuleList::GetModuleAtIndex
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
Definition: ModuleList.cpp:353
CommandInterpreter.h
lldb_private::CommandInterpreter::GetExecutionContext
ExecutionContext GetExecutionContext() const
lldb_private::eVarSetOperationInvalid
@ eVarSetOperationInvalid
Definition: lldb-private-enumerations.h:91
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb
Definition: SBAddress.h:15
lldb_private::eVarSetOperationClear
@ eVarSetOperationClear
Definition: lldb-private-enumerations.h:89
lldb_private::ExecutionContext::GetTargetPtr
Target * GetTargetPtr() const
Returns a pointer to the target object.
Definition: ExecutionContext.cpp:200
DumpValue
static bool DumpValue(Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const FormatEntity::Entry &entry, ValueObject *valobj)
Definition: FormatEntity.cpp:673
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::eVarSetOperationInsertAfter
@ eVarSetOperationInsertAfter
Definition: lldb-private-enumerations.h:86
lldb_private::eVarSetOperationAssign
@ eVarSetOperationAssign
Definition: lldb-private-enumerations.h:90