blob: 0141911d97adf0aff973bacec10e482a84c56b50 [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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton67cc0632012-08-22 17:17:09 +000012#include "lldb/Interpreter/OptionValueUUID.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Greg Claytonb5f0fea2012-09-27 22:26:11 +000018#include "lldb/Core/Module.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000019#include "lldb/Core/Stream.h"
Greg Claytonb5f0fea2012-09-27 22:26:11 +000020#include "lldb/Core/StringList.h"
21#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000022
23using namespace lldb;
24using namespace lldb_private;
25
26void
27OptionValueUUID::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
28{
29 if (dump_mask & eDumpOptionType)
30 strm.Printf ("(%s)", GetTypeAsCString ());
31 if (dump_mask & eDumpOptionValue)
32 {
33 if (dump_mask & eDumpOptionType)
34 strm.PutCString (" = ");
35 m_uuid.Dump (&strm);
36 }
37}
38
39Error
40OptionValueUUID::SetValueFromCString (const char *value_cstr,
41 VarSetOperationType op)
42{
43 Error error;
44 switch (op)
45 {
46 case eVarSetOperationClear:
47 Clear();
48 break;
49
50 case eVarSetOperationReplace:
51 case eVarSetOperationAssign:
52 {
Greg Claytonb5f0fea2012-09-27 22:26:11 +000053 if (m_uuid.SetFromCString(value_cstr) == 0)
Greg Clayton67cc0632012-08-22 17:17:09 +000054 error.SetErrorStringWithFormat ("invalid uuid string value '%s'", value_cstr);
55 else
56 m_value_was_set = true;
57 }
58 break;
59
60 case eVarSetOperationInsertBefore:
61 case eVarSetOperationInsertAfter:
62 case eVarSetOperationRemove:
63 case eVarSetOperationAppend:
64 case eVarSetOperationInvalid:
65 error = OptionValue::SetValueFromCString (value_cstr, op);
66 break;
67 }
68 return error;
69}
70
71lldb::OptionValueSP
72OptionValueUUID::DeepCopy () const
73{
74 return OptionValueSP(new OptionValueUUID(*this));
75}
Greg Claytonb5f0fea2012-09-27 22:26:11 +000076
77size_t
78OptionValueUUID::AutoComplete (CommandInterpreter &interpreter,
79 const char *s,
80 int match_start_point,
81 int max_return_elements,
82 bool &word_complete,
83 StringList &matches)
84{
85 word_complete = false;
86 matches.Clear();
87 ExecutionContext exe_ctx(interpreter.GetExecutionContext());
88 Target *target = exe_ctx.GetTargetPtr();
89 if (target)
90 {
91 const size_t num_modules = target->GetImages().GetSize();
92 if (num_modules > 0)
93 {
Greg Claytonb5f0fea2012-09-27 22:26:11 +000094 UUID::ValueType uuid_bytes;
Ed Masted78c9572014-04-20 00:31:37 +000095 const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, nullptr);
Greg Claytonb5f0fea2012-09-27 22:26:11 +000096 for (size_t i=0; i<num_modules; ++i)
97 {
98 ModuleSP module_sp (target->GetImages().GetModuleAtIndex(i));
99 if (module_sp)
100 {
101 const UUID &module_uuid = module_sp->GetUUID();
102 if (module_uuid.IsValid())
103 {
104 bool add_uuid = false;
105 if (num_bytes_decoded == 0)
106 add_uuid = true;
107 else
108 add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0;
109 if (add_uuid)
110 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000111 std::string uuid_str;
112 uuid_str = module_uuid.GetAsString();
113 if (!uuid_str.empty())
114 matches.AppendString(uuid_str.c_str());
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000115 }
116 }
117 }
118 }
119 }
120 }
121 return matches.GetSize();
122}
123