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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 25 | uint32_t dump_mask) { |
| 26 | if (dump_mask & eDumpOptionType) |
| 27 | strm.Printf("(%s)", GetTypeAsCString()); |
| 28 | if (dump_mask & eDumpOptionValue) { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 29 | if (dump_mask & eDumpOptionType) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | strm.PutCString(" = "); |
| 31 | m_uuid.Dump(&strm); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | Error OptionValueUUID::SetValueFromString(llvm::StringRef value, |
| 36 | VarSetOperationType op) { |
| 37 | Error error; |
| 38 | switch (op) { |
| 39 | case eVarSetOperationClear: |
| 40 | Clear(); |
| 41 | NotifyValueChanged(); |
| 42 | break; |
| 43 | |
| 44 | case eVarSetOperationReplace: |
| 45 | case eVarSetOperationAssign: { |
| 46 | if (m_uuid.SetFromCString(value.str().c_str()) == 0) |
| 47 | error.SetErrorStringWithFormat("invalid uuid string value '%s'", |
| 48 | value.str().c_str()); |
| 49 | else { |
| 50 | m_value_was_set = true; |
| 51 | NotifyValueChanged(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 52 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 53 | } break; |
| 54 | |
| 55 | case eVarSetOperationInsertBefore: |
| 56 | case eVarSetOperationInsertAfter: |
| 57 | case eVarSetOperationRemove: |
| 58 | case eVarSetOperationAppend: |
| 59 | case eVarSetOperationInvalid: |
| 60 | error = OptionValue::SetValueFromString(value, op); |
| 61 | break; |
| 62 | } |
| 63 | return error; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | lldb::OptionValueSP OptionValueUUID::DeepCopy() const { |
| 67 | return OptionValueSP(new OptionValueUUID(*this)); |
| 68 | } |
| 69 | |
| 70 | size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter, |
Zachary Turner | 4aa8753 | 2016-11-17 01:37:42 +0000 | [diff] [blame] | 71 | llvm::StringRef s, int match_start_point, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 72 | int max_return_elements, |
| 73 | bool &word_complete, StringList &matches) { |
| 74 | word_complete = false; |
| 75 | matches.Clear(); |
| 76 | ExecutionContext exe_ctx(interpreter.GetExecutionContext()); |
| 77 | Target *target = exe_ctx.GetTargetPtr(); |
| 78 | if (target) { |
| 79 | const size_t num_modules = target->GetImages().GetSize(); |
| 80 | if (num_modules > 0) { |
| 81 | UUID::ValueType uuid_bytes; |
Zachary Turner | 0eb31a1 | 2016-11-17 05:14:32 +0000 | [diff] [blame] | 82 | uint32_t num_bytes_decoded = 0; |
| 83 | UUID::DecodeUUIDBytesFromString(s, uuid_bytes, num_bytes_decoded); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | for (size_t i = 0; i < num_modules; ++i) { |
| 85 | ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i)); |
| 86 | if (module_sp) { |
| 87 | const UUID &module_uuid = module_sp->GetUUID(); |
| 88 | if (module_uuid.IsValid()) { |
| 89 | bool add_uuid = false; |
| 90 | if (num_bytes_decoded == 0) |
| 91 | add_uuid = true; |
| 92 | else |
| 93 | add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, |
| 94 | num_bytes_decoded) == 0; |
| 95 | if (add_uuid) { |
| 96 | std::string uuid_str; |
| 97 | uuid_str = module_uuid.GetAsString(); |
| 98 | if (!uuid_str.empty()) |
| 99 | matches.AppendString(uuid_str.c_str()); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 100 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 102 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 104 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | } |
| 106 | return matches.GetSize(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 107 | } |