blob: c228cf6e415e0189551d523fe368b357bce2a423 [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();
Greg Clayton332e8b12015-01-13 21:13:08 +000048 NotifyValueChanged();
Greg Clayton67cc0632012-08-22 17:17:09 +000049 break;
50
51 case eVarSetOperationReplace:
52 case eVarSetOperationAssign:
53 {
Greg Claytonb5f0fea2012-09-27 22:26:11 +000054 if (m_uuid.SetFromCString(value_cstr) == 0)
Greg Clayton67cc0632012-08-22 17:17:09 +000055 error.SetErrorStringWithFormat ("invalid uuid string value '%s'", value_cstr);
56 else
Greg Clayton332e8b12015-01-13 21:13:08 +000057 {
Greg Clayton67cc0632012-08-22 17:17:09 +000058 m_value_was_set = true;
Greg Clayton332e8b12015-01-13 21:13:08 +000059 NotifyValueChanged();
60 }
Greg Clayton67cc0632012-08-22 17:17:09 +000061 }
62 break;
63
64 case eVarSetOperationInsertBefore:
65 case eVarSetOperationInsertAfter:
66 case eVarSetOperationRemove:
67 case eVarSetOperationAppend:
68 case eVarSetOperationInvalid:
69 error = OptionValue::SetValueFromCString (value_cstr, op);
70 break;
71 }
72 return error;
73}
74
75lldb::OptionValueSP
76OptionValueUUID::DeepCopy () const
77{
78 return OptionValueSP(new OptionValueUUID(*this));
79}
Greg Claytonb5f0fea2012-09-27 22:26:11 +000080
81size_t
82OptionValueUUID::AutoComplete (CommandInterpreter &interpreter,
83 const char *s,
84 int match_start_point,
85 int max_return_elements,
86 bool &word_complete,
87 StringList &matches)
88{
89 word_complete = false;
90 matches.Clear();
91 ExecutionContext exe_ctx(interpreter.GetExecutionContext());
92 Target *target = exe_ctx.GetTargetPtr();
93 if (target)
94 {
95 const size_t num_modules = target->GetImages().GetSize();
96 if (num_modules > 0)
97 {
Greg Claytonb5f0fea2012-09-27 22:26:11 +000098 UUID::ValueType uuid_bytes;
Ed Masted78c9572014-04-20 00:31:37 +000099 const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, nullptr);
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000100 for (size_t i=0; i<num_modules; ++i)
101 {
102 ModuleSP module_sp (target->GetImages().GetModuleAtIndex(i));
103 if (module_sp)
104 {
105 const UUID &module_uuid = module_sp->GetUUID();
106 if (module_uuid.IsValid())
107 {
108 bool add_uuid = false;
109 if (num_bytes_decoded == 0)
110 add_uuid = true;
111 else
112 add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0;
113 if (add_uuid)
114 {
Jason Molendac16b4af2013-05-03 23:56:12 +0000115 std::string uuid_str;
116 uuid_str = module_uuid.GetAsString();
117 if (!uuid_str.empty())
118 matches.AppendString(uuid_str.c_str());
Greg Claytonb5f0fea2012-09-27 22:26:11 +0000119 }
120 }
121 }
122 }
123 }
124 }
125 return matches.GetSize();
126}
127