1ac7ddfbfSEd Maste //===-- OptionValueUUID.cpp ------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/Interpreter/OptionValueUUID.h"
11ac7ddfbfSEd Maste
12ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
13ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
14f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
15f678e45dSDimitry Andric #include "lldb/Utility/StringList.h"
16ac7ddfbfSEd Maste
17ac7ddfbfSEd Maste using namespace lldb;
18ac7ddfbfSEd Maste using namespace lldb_private;
19ac7ddfbfSEd Maste
DumpValue(const ExecutionContext * exe_ctx,Stream & strm,uint32_t dump_mask)20435933ddSDimitry Andric void OptionValueUUID::DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
21435933ddSDimitry Andric uint32_t dump_mask) {
22ac7ddfbfSEd Maste if (dump_mask & eDumpOptionType)
23ac7ddfbfSEd Maste strm.Printf("(%s)", GetTypeAsCString());
24435933ddSDimitry Andric if (dump_mask & eDumpOptionValue) {
25ac7ddfbfSEd Maste if (dump_mask & eDumpOptionType)
26ac7ddfbfSEd Maste strm.PutCString(" = ");
27ac7ddfbfSEd Maste m_uuid.Dump(&strm);
28ac7ddfbfSEd Maste }
29ac7ddfbfSEd Maste }
30ac7ddfbfSEd Maste
SetValueFromString(llvm::StringRef value,VarSetOperationType op)315517e702SDimitry Andric Status OptionValueUUID::SetValueFromString(llvm::StringRef value,
32435933ddSDimitry Andric VarSetOperationType op) {
335517e702SDimitry Andric Status error;
34435933ddSDimitry Andric switch (op) {
35ac7ddfbfSEd Maste case eVarSetOperationClear:
36ac7ddfbfSEd Maste Clear();
377aa51b79SEd Maste NotifyValueChanged();
38ac7ddfbfSEd Maste break;
39ac7ddfbfSEd Maste
40ac7ddfbfSEd Maste case eVarSetOperationReplace:
41435933ddSDimitry Andric case eVarSetOperationAssign: {
42*4ba319b5SDimitry Andric if (m_uuid.SetFromStringRef(value) == 0)
43435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid uuid string value '%s'",
44435933ddSDimitry Andric value.str().c_str());
45435933ddSDimitry Andric else {
46ac7ddfbfSEd Maste m_value_was_set = true;
477aa51b79SEd Maste NotifyValueChanged();
487aa51b79SEd Maste }
49435933ddSDimitry Andric } break;
50ac7ddfbfSEd Maste
51ac7ddfbfSEd Maste case eVarSetOperationInsertBefore:
52ac7ddfbfSEd Maste case eVarSetOperationInsertAfter:
53ac7ddfbfSEd Maste case eVarSetOperationRemove:
54ac7ddfbfSEd Maste case eVarSetOperationAppend:
55ac7ddfbfSEd Maste case eVarSetOperationInvalid:
561c3bbb01SEd Maste error = OptionValue::SetValueFromString(value, op);
57ac7ddfbfSEd Maste break;
58ac7ddfbfSEd Maste }
59ac7ddfbfSEd Maste return error;
60ac7ddfbfSEd Maste }
61ac7ddfbfSEd Maste
DeepCopy() const62435933ddSDimitry Andric lldb::OptionValueSP OptionValueUUID::DeepCopy() const {
63ac7ddfbfSEd Maste return OptionValueSP(new OptionValueUUID(*this));
64ac7ddfbfSEd Maste }
65ac7ddfbfSEd Maste
AutoComplete(CommandInterpreter & interpreter,CompletionRequest & request)66435933ddSDimitry Andric size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
67*4ba319b5SDimitry Andric CompletionRequest &request) {
68*4ba319b5SDimitry Andric request.SetWordComplete(false);
69ac7ddfbfSEd Maste ExecutionContext exe_ctx(interpreter.GetExecutionContext());
70ac7ddfbfSEd Maste Target *target = exe_ctx.GetTargetPtr();
71435933ddSDimitry Andric if (target) {
72*4ba319b5SDimitry Andric auto prefix = request.GetCursorArgumentPrefix();
73*4ba319b5SDimitry Andric llvm::SmallVector<uint8_t, 20> uuid_bytes;
74*4ba319b5SDimitry Andric if (UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty()) {
75ac7ddfbfSEd Maste const size_t num_modules = target->GetImages().GetSize();
76435933ddSDimitry Andric for (size_t i = 0; i < num_modules; ++i) {
77ac7ddfbfSEd Maste ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
78435933ddSDimitry Andric if (module_sp) {
79ac7ddfbfSEd Maste const UUID &module_uuid = module_sp->GetUUID();
80435933ddSDimitry Andric if (module_uuid.IsValid()) {
81*4ba319b5SDimitry Andric llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes();
82*4ba319b5SDimitry Andric if (module_bytes.size() >= uuid_bytes.size() &&
83*4ba319b5SDimitry Andric module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) {
84*4ba319b5SDimitry Andric request.AddCompletion(module_uuid.GetAsString());
85ac7ddfbfSEd Maste }
86ac7ddfbfSEd Maste }
87ac7ddfbfSEd Maste }
88ac7ddfbfSEd Maste }
89ac7ddfbfSEd Maste }
90ac7ddfbfSEd Maste }
91*4ba319b5SDimitry Andric return request.GetNumberOfMatches();
92ac7ddfbfSEd Maste }
93