Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Module.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Stream.h" |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 18 | #include "lldb/Core/StringList.h" |
| 19 | #include "lldb/Interpreter/CommandInterpreter.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 |
Pavel Labath | c95f7e2 | 2015-02-20 11:14:59 +0000 | [diff] [blame] | 38 | OptionValueUUID::SetValueFromString (llvm::StringRef value, |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 39 | VarSetOperationType op) |
| 40 | { |
| 41 | Error error; |
| 42 | switch (op) |
| 43 | { |
| 44 | case eVarSetOperationClear: |
| 45 | Clear(); |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 46 | NotifyValueChanged(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 47 | break; |
| 48 | |
| 49 | case eVarSetOperationReplace: |
| 50 | case eVarSetOperationAssign: |
| 51 | { |
Pavel Labath | c95f7e2 | 2015-02-20 11:14:59 +0000 | [diff] [blame] | 52 | if (m_uuid.SetFromCString(value.str().c_str()) == 0) |
| 53 | error.SetErrorStringWithFormat ("invalid uuid string value '%s'", value.str().c_str()); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 54 | else |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 55 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 56 | m_value_was_set = true; |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 57 | NotifyValueChanged(); |
| 58 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 59 | } |
| 60 | break; |
| 61 | |
| 62 | case eVarSetOperationInsertBefore: |
| 63 | case eVarSetOperationInsertAfter: |
| 64 | case eVarSetOperationRemove: |
| 65 | case eVarSetOperationAppend: |
| 66 | case eVarSetOperationInvalid: |
Pavel Labath | c95f7e2 | 2015-02-20 11:14:59 +0000 | [diff] [blame] | 67 | error = OptionValue::SetValueFromString (value, op); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 68 | break; |
| 69 | } |
| 70 | return error; |
| 71 | } |
| 72 | |
| 73 | lldb::OptionValueSP |
| 74 | OptionValueUUID::DeepCopy () const |
| 75 | { |
| 76 | return OptionValueSP(new OptionValueUUID(*this)); |
| 77 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 78 | |
| 79 | size_t |
| 80 | OptionValueUUID::AutoComplete (CommandInterpreter &interpreter, |
| 81 | const char *s, |
| 82 | int match_start_point, |
| 83 | int max_return_elements, |
| 84 | bool &word_complete, |
| 85 | StringList &matches) |
| 86 | { |
| 87 | word_complete = false; |
| 88 | matches.Clear(); |
| 89 | ExecutionContext exe_ctx(interpreter.GetExecutionContext()); |
| 90 | Target *target = exe_ctx.GetTargetPtr(); |
| 91 | if (target) |
| 92 | { |
| 93 | const size_t num_modules = target->GetImages().GetSize(); |
| 94 | if (num_modules > 0) |
| 95 | { |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 96 | UUID::ValueType uuid_bytes; |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 97 | const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, nullptr); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 98 | for (size_t i=0; i<num_modules; ++i) |
| 99 | { |
| 100 | ModuleSP module_sp (target->GetImages().GetModuleAtIndex(i)); |
| 101 | if (module_sp) |
| 102 | { |
| 103 | const UUID &module_uuid = module_sp->GetUUID(); |
| 104 | if (module_uuid.IsValid()) |
| 105 | { |
| 106 | bool add_uuid = false; |
| 107 | if (num_bytes_decoded == 0) |
| 108 | add_uuid = true; |
| 109 | else |
| 110 | add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0; |
| 111 | if (add_uuid) |
| 112 | { |
Jason Molenda | c16b4af | 2013-05-03 23:56:12 +0000 | [diff] [blame] | 113 | std::string uuid_str; |
| 114 | uuid_str = module_uuid.GetAsString(); |
| 115 | if (!uuid_str.empty()) |
| 116 | matches.AppendString(uuid_str.c_str()); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | return matches.GetSize(); |
| 124 | } |
| 125 | |