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 | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 17 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Stream.h" |
Zachary Turner | 573ab90 | 2017-03-21 18:25:04 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/StringList.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 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 35 | Status OptionValueUUID::SetValueFromString(llvm::StringRef value, |
| 36 | VarSetOperationType op) { |
| 37 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | switch (op) { |
| 39 | case eVarSetOperationClear: |
| 40 | Clear(); |
| 41 | NotifyValueChanged(); |
| 42 | break; |
| 43 | |
| 44 | case eVarSetOperationReplace: |
| 45 | case eVarSetOperationAssign: { |
Pavel Labath | a174bcb | 2018-06-21 15:24:39 +0000 | [diff] [blame] | 46 | if (m_uuid.SetFromStringRef(value) == 0) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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, |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame^] | 71 | CompletionRequest &request) { |
| 72 | request.SetWordComplete(false); |
| 73 | request.GetMatches().Clear(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | ExecutionContext exe_ctx(interpreter.GetExecutionContext()); |
| 75 | Target *target = exe_ctx.GetTargetPtr(); |
| 76 | if (target) { |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame^] | 77 | auto prefix = request.GetCursorArgumentPrefix(); |
Pavel Labath | 77c397f | 2018-06-29 11:20:29 +0000 | [diff] [blame] | 78 | llvm::SmallVector<uint8_t, 20> uuid_bytes; |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame^] | 79 | if (UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty()) { |
Pavel Labath | 77c397f | 2018-06-29 11:20:29 +0000 | [diff] [blame] | 80 | const size_t num_modules = target->GetImages().GetSize(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | for (size_t i = 0; i < num_modules; ++i) { |
| 82 | ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i)); |
| 83 | if (module_sp) { |
| 84 | const UUID &module_uuid = module_sp->GetUUID(); |
| 85 | if (module_uuid.IsValid()) { |
Pavel Labath | 470b286 | 2018-06-21 15:07:43 +0000 | [diff] [blame] | 86 | llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes(); |
Pavel Labath | 77c397f | 2018-06-29 11:20:29 +0000 | [diff] [blame] | 87 | if (module_bytes.size() >= uuid_bytes.size() && |
| 88 | module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) { |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame^] | 89 | request.GetMatches().AppendString(module_uuid.GetAsString()); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 90 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 91 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 92 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | } |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 94 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | } |
Raphael Isemann | a2e76c0 | 2018-07-13 18:28:14 +0000 | [diff] [blame^] | 96 | return request.GetMatches().GetSize(); |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 97 | } |