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 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Module.h" 17 #include "lldb/Core/Stream.h" 18 #include "lldb/Core/StringList.h" 19 #include "lldb/Interpreter/CommandInterpreter.h" 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 void 25 OptionValueUUID::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 26 { 27 if (dump_mask & eDumpOptionType) 28 strm.Printf ("(%s)", GetTypeAsCString ()); 29 if (dump_mask & eDumpOptionValue) 30 { 31 if (dump_mask & eDumpOptionType) 32 strm.PutCString (" = "); 33 m_uuid.Dump (&strm); 34 } 35 } 36 37 Error 38 OptionValueUUID::SetValueFromCString (const char *value_cstr, 39 VarSetOperationType op) 40 { 41 Error error; 42 switch (op) 43 { 44 case eVarSetOperationClear: 45 Clear(); 46 break; 47 48 case eVarSetOperationReplace: 49 case eVarSetOperationAssign: 50 { 51 if (m_uuid.SetFromCString(value_cstr) == 0) 52 error.SetErrorStringWithFormat ("invalid uuid string value '%s'", value_cstr); 53 else 54 m_value_was_set = true; 55 } 56 break; 57 58 case eVarSetOperationInsertBefore: 59 case eVarSetOperationInsertAfter: 60 case eVarSetOperationRemove: 61 case eVarSetOperationAppend: 62 case eVarSetOperationInvalid: 63 error = OptionValue::SetValueFromCString (value_cstr, op); 64 break; 65 } 66 return error; 67 } 68 69 lldb::OptionValueSP 70 OptionValueUUID::DeepCopy () const 71 { 72 return OptionValueSP(new OptionValueUUID(*this)); 73 } 74 75 size_t 76 OptionValueUUID::AutoComplete (CommandInterpreter &interpreter, 77 const char *s, 78 int match_start_point, 79 int max_return_elements, 80 bool &word_complete, 81 StringList &matches) 82 { 83 word_complete = false; 84 matches.Clear(); 85 ExecutionContext exe_ctx(interpreter.GetExecutionContext()); 86 Target *target = exe_ctx.GetTargetPtr(); 87 if (target) 88 { 89 const size_t num_modules = target->GetImages().GetSize(); 90 if (num_modules > 0) 91 { 92 char uuid_cstr[64]; 93 UUID::ValueType uuid_bytes; 94 const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, NULL); 95 for (size_t i=0; i<num_modules; ++i) 96 { 97 ModuleSP module_sp (target->GetImages().GetModuleAtIndex(i)); 98 if (module_sp) 99 { 100 const UUID &module_uuid = module_sp->GetUUID(); 101 if (module_uuid.IsValid()) 102 { 103 bool add_uuid = false; 104 if (num_bytes_decoded == 0) 105 add_uuid = true; 106 else 107 add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0; 108 if (add_uuid) 109 { 110 if (module_uuid.GetAsCString(uuid_cstr, sizeof(uuid_cstr))) 111 matches.AppendString(uuid_cstr); 112 } 113 } 114 } 115 } 116 } 117 } 118 return matches.GetSize(); 119 } 120 121