1 //===-- OptionValueUUID.cpp ------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Interpreter/OptionValueUUID.h" 11 12 #include "lldb/Core/Module.h" 13 #include "lldb/Interpreter/CommandInterpreter.h" 14 #include "lldb/Utility/Stream.h" 15 #include "lldb/Utility/StringList.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 21 uint32_t dump_mask) { 22 if (dump_mask & eDumpOptionType) 23 strm.Printf("(%s)", GetTypeAsCString()); 24 if (dump_mask & eDumpOptionValue) { 25 if (dump_mask & eDumpOptionType) 26 strm.PutCString(" = "); 27 m_uuid.Dump(&strm); 28 } 29 } 30 31 Status OptionValueUUID::SetValueFromString(llvm::StringRef value, 32 VarSetOperationType op) { 33 Status error; 34 switch (op) { 35 case eVarSetOperationClear: 36 Clear(); 37 NotifyValueChanged(); 38 break; 39 40 case eVarSetOperationReplace: 41 case eVarSetOperationAssign: { 42 if (m_uuid.SetFromStringRef(value) == 0) 43 error.SetErrorStringWithFormat("invalid uuid string value '%s'", 44 value.str().c_str()); 45 else { 46 m_value_was_set = true; 47 NotifyValueChanged(); 48 } 49 } break; 50 51 case eVarSetOperationInsertBefore: 52 case eVarSetOperationInsertAfter: 53 case eVarSetOperationRemove: 54 case eVarSetOperationAppend: 55 case eVarSetOperationInvalid: 56 error = OptionValue::SetValueFromString(value, op); 57 break; 58 } 59 return error; 60 } 61 62 lldb::OptionValueSP OptionValueUUID::DeepCopy() const { 63 return OptionValueSP(new OptionValueUUID(*this)); 64 } 65 66 size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter, 67 CompletionRequest &request) { 68 request.SetWordComplete(false); 69 ExecutionContext exe_ctx(interpreter.GetExecutionContext()); 70 Target *target = exe_ctx.GetTargetPtr(); 71 if (target) { 72 auto prefix = request.GetCursorArgumentPrefix(); 73 llvm::SmallVector<uint8_t, 20> uuid_bytes; 74 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)); 78 if (module_sp) { 79 const UUID &module_uuid = module_sp->GetUUID(); 80 if (module_uuid.IsValid()) { 81 llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes(); 82 if (module_bytes.size() >= uuid_bytes.size() && 83 module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) { 84 request.AddCompletion(module_uuid.GetAsString()); 85 } 86 } 87 } 88 } 89 } 90 } 91 return request.GetNumberOfMatches(); 92 } 93