| 1 | //===-- OptionValueUUID.cpp -----------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Interpreter/OptionValueUUID.h" |
| 10 | |
| 11 | #include "lldb/Core/Module.h" |
| 12 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 13 | #include "lldb/Utility/Stream.h" |
| 14 | #include "lldb/Utility/StringList.h" |
| 15 | |
| 16 | using namespace lldb; |
| 17 | using namespace lldb_private; |
| 18 | |
| 19 | void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm, |
| 20 | uint32_t dump_mask) { |
| 21 | if (dump_mask & eDumpOptionType) |
| 22 | strm.Printf(format: "(%s)" , GetTypeAsCString()); |
| 23 | if (dump_mask & eDumpOptionValue) { |
| 24 | if (dump_mask & eDumpOptionType) |
| 25 | strm.PutCString(cstr: " = " ); |
| 26 | m_uuid.Dump(s&: strm); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | Status OptionValueUUID::SetValueFromString(llvm::StringRef value, |
| 31 | VarSetOperationType op) { |
| 32 | Status error; |
| 33 | switch (op) { |
| 34 | case eVarSetOperationClear: |
| 35 | Clear(); |
| 36 | NotifyValueChanged(); |
| 37 | break; |
| 38 | |
| 39 | case eVarSetOperationReplace: |
| 40 | case eVarSetOperationAssign: { |
| 41 | if (!m_uuid.SetFromStringRef(value)) |
| 42 | error = Status::FromErrorStringWithFormat( |
| 43 | format: "invalid uuid string value '%s'" , value.str().c_str()); |
| 44 | else { |
| 45 | m_value_was_set = true; |
| 46 | NotifyValueChanged(); |
| 47 | } |
| 48 | } break; |
| 49 | |
| 50 | case eVarSetOperationInsertBefore: |
| 51 | case eVarSetOperationInsertAfter: |
| 52 | case eVarSetOperationRemove: |
| 53 | case eVarSetOperationAppend: |
| 54 | case eVarSetOperationInvalid: |
| 55 | error = OptionValue::SetValueFromString(value, op); |
| 56 | break; |
| 57 | } |
| 58 | return error; |
| 59 | } |
| 60 | |
| 61 | void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter, |
| 62 | CompletionRequest &request) { |
| 63 | ExecutionContext exe_ctx(interpreter.GetExecutionContext()); |
| 64 | Target *target = exe_ctx.GetTargetPtr(); |
| 65 | if (!target) |
| 66 | return; |
| 67 | auto prefix = request.GetCursorArgumentPrefix(); |
| 68 | llvm::SmallVector<uint8_t, 20> uuid_bytes; |
| 69 | if (!UUID::DecodeUUIDBytesFromString(str: prefix, uuid_bytes).empty()) |
| 70 | return; |
| 71 | const size_t num_modules = target->GetImages().GetSize(); |
| 72 | for (size_t i = 0; i < num_modules; ++i) { |
| 73 | ModuleSP module_sp(target->GetImages().GetModuleAtIndex(idx: i)); |
| 74 | if (!module_sp) |
| 75 | continue; |
| 76 | const UUID &module_uuid = module_sp->GetUUID(); |
| 77 | if (!module_uuid.IsValid()) |
| 78 | continue; |
| 79 | request.TryCompleteCurrentArg(completion: module_uuid.GetAsString()); |
| 80 | } |
| 81 | } |
| 82 | |