blob: b16a9eb7e99407f77ee8d57cf69dd148b6260c14 [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- 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 Claytonb5f0fea2012-09-27 22:26:11 +000016#include "lldb/Core/Module.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000017#include "lldb/Core/Stream.h"
Greg Claytonb5f0fea2012-09-27 22:26:11 +000018#include "lldb/Core/StringList.h"
19#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000020
21using namespace lldb;
22using namespace lldb_private;
23
24void
25OptionValueUUID::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
37Error
Pavel Labathc95f7e22015-02-20 11:14:59 +000038OptionValueUUID::SetValueFromString (llvm::StringRef value,
Greg Clayton67cc0632012-08-22 17:17:09 +000039 VarSetOperationType op)
40{
41 Error error;
42 switch (op)
43 {
44 case eVarSetOperationClear:
45 Clear();
Greg Clayton332e8b12015-01-13 21:13:08 +000046 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000047 break;
48
49 case eVarSetOperationReplace:
50 case eVarSetOperationAssign:
51 {
Pavel Labathc95f7e22015-02-20 11:14:59 +000052 if (m_uuid.SetFromCString(value.str().c_str()) == 0)
53 error.SetErrorStringWithFormat ("invalid uuid string value '%s'", value.str().c_str());
Greg Clayton67cc0632012-08-22 17:17:09 +000054 else
Greg Clayton332e8b12015-01-13 21:13:08 +000055 {
Greg Clayton67cc0632012-08-22 17:17:09 +000056 m_value_was_set = true;
Greg Clayton332e8b12015-01-13 21:13:08 +000057 NotifyValueChanged();
58 }
Greg Clayton67cc0632012-08-22 17:17:09 +000059 }
60 break;
61
62 case eVarSetOperationInsertBefore:
63 case eVarSetOperationInsertAfter:
64 case eVarSetOperationRemove:
65 case eVarSetOperationAppend:
66 case eVarSetOperationInvalid:
Pavel Labathc95f7e22015-02-20 11:14:59 +000067 error = OptionValue::SetValueFromString (value, op);
Greg Clayton67cc0632012-08-22 17:17:09 +000068 break;
69 }
70 return error;
71}
72
73lldb::OptionValueSP
74OptionValueUUID::DeepCopy () const
75{
76 return OptionValueSP(new OptionValueUUID(*this));
77}
Greg Claytonb5f0fea2012-09-27 22:26:11 +000078
79size_t
80OptionValueUUID::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 Claytonb5f0fea2012-09-27 22:26:11 +000096 UUID::ValueType uuid_bytes;
Ed Masted78c9572014-04-20 00:31:37 +000097 const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, nullptr);
Greg Claytonb5f0fea2012-09-27 22:26:11 +000098 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 Molendac16b4af2013-05-03 23:56:12 +0000113 std::string uuid_str;
114 uuid_str = module_uuid.GetAsString();
115 if (!uuid_str.empty())
116 matches.AppendString(uuid_str.c_str());
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000117 }
118 }
119 }
120 }
121 }
122 }
123 return matches.GetSize();
124}
125