blob: 0e3c9cb8336452fcf662ba77e14a61c0abad3940 [file] [log] [blame]
Greg Clayton73844aa2012-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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Clayton73844aa2012-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 Clayton437b5bc2012-09-27 22:26:11 +000018#include "lldb/Core/Module.h"
Greg Clayton73844aa2012-08-22 17:17:09 +000019#include "lldb/Core/Stream.h"
Greg Clayton437b5bc2012-09-27 22:26:11 +000020#include "lldb/Core/StringList.h"
21#include "lldb/Interpreter/CommandInterpreter.h"
Greg Clayton73844aa2012-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 Clayton437b5bc2012-09-27 22:26:11 +000053 if (m_uuid.SetFromCString(value_cstr) == 0)
Greg Clayton73844aa2012-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 Clayton437b5bc2012-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 {
94 char uuid_cstr[64];
95 UUID::ValueType uuid_bytes;
96 const size_t num_bytes_decoded = UUID::DecodeUUIDBytesFromCString(s, uuid_bytes, NULL);
97 for (size_t i=0; i<num_modules; ++i)
98 {
99 ModuleSP module_sp (target->GetImages().GetModuleAtIndex(i));
100 if (module_sp)
101 {
102 const UUID &module_uuid = module_sp->GetUUID();
103 if (module_uuid.IsValid())
104 {
105 bool add_uuid = false;
106 if (num_bytes_decoded == 0)
107 add_uuid = true;
108 else
109 add_uuid = ::memcmp(module_uuid.GetBytes(), uuid_bytes, num_bytes_decoded) == 0;
110 if (add_uuid)
111 {
112 if (module_uuid.GetAsCString(uuid_cstr, sizeof(uuid_cstr)))
113 matches.AppendString(uuid_cstr);
114 }
115 }
116 }
117 }
118 }
119 }
120 return matches.GetSize();
121}
122