1 //===-- OptionValueUUID.cpp ------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionValueUUID.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Utility/Stream.h"
14 #include "lldb/Utility/StringList.h"
17 using namespace lldb_private;
19 void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
21 if (dump_mask & eDumpOptionType)
22 strm.Printf("(%s)", GetTypeAsCString());
23 if (dump_mask & eDumpOptionValue) {
24 if (dump_mask & eDumpOptionType)
25 strm.PutCString(" = ");
30 Status OptionValueUUID::SetValueFromString(llvm::StringRef value,
31 VarSetOperationType op) {
34 case eVarSetOperationClear:
39 case eVarSetOperationReplace:
40 case eVarSetOperationAssign: {
41 if (m_uuid.SetFromStringRef(value) == 0)
42 error.SetErrorStringWithFormat("invalid uuid string value '%s'",
45 m_value_was_set = true;
50 case eVarSetOperationInsertBefore:
51 case eVarSetOperationInsertAfter:
52 case eVarSetOperationRemove:
53 case eVarSetOperationAppend:
54 case eVarSetOperationInvalid:
55 error = OptionValue::SetValueFromString(value, op);
61 lldb::OptionValueSP OptionValueUUID::DeepCopy() const {
62 return OptionValueSP(new OptionValueUUID(*this));
65 void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
66 CompletionRequest &request) {
67 ExecutionContext exe_ctx(interpreter.GetExecutionContext());
68 Target *target = exe_ctx.GetTargetPtr();
71 auto prefix = request.GetCursorArgumentPrefix();
72 llvm::SmallVector<uint8_t, 20> uuid_bytes;
73 if (!UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty())
75 const size_t num_modules = target->GetImages().GetSize();
76 for (size_t i = 0; i < num_modules; ++i) {
77 ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
80 const UUID &module_uuid = module_sp->GetUUID();
81 if (!module_uuid.IsValid())
83 request.TryCompleteCurrentArg(module_uuid.GetAsString());