blob: 5679ef8dd3ba957e3267cbb933b4d3f5e3b8dabd [file] [log] [blame]
Greg Clayton67cc0632012-08-22 17:17:09 +00001//===-- Property.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/Property.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
18#include "lldb/Core/UserSettingsController.h"
Vince Harron5275aaa2015-01-15 20:08:35 +000019#include "lldb/Host/StringConvert.h"
Greg Clayton67cc0632012-08-22 17:17:09 +000020#include "lldb/Interpreter/CommandInterpreter.h"
21#include "lldb/Interpreter/OptionValues.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26Property::Property (const PropertyDefinition &definition) :
27 m_name (definition.name),
28 m_description (definition.description),
29 m_value_sp (),
30 m_is_global (definition.global)
31{
32 switch (definition.type)
33 {
34 case OptionValue::eTypeInvalid:
35 case OptionValue::eTypeProperties:
36 break;
37 case OptionValue::eTypeArch:
38 // "definition.default_uint_value" is not used
39 // "definition.default_cstr_value" as a string value that represents the default string value for the architecture/triple
40 m_value_sp.reset (new OptionValueArch(definition.default_cstr_value));
41 break;
42
43 case OptionValue::eTypeArgs:
44 // "definition.default_uint_value" is always a OptionValue::Type
45 m_value_sp.reset (new OptionValueArgs());
46 break;
47
48 case OptionValue::eTypeArray:
49 // "definition.default_uint_value" is always a OptionValue::Type
50 m_value_sp.reset (new OptionValueArray(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
51 break;
52
53 case OptionValue::eTypeBoolean:
54 // "definition.default_uint_value" is the default boolean value if
55 // "definition.default_cstr_value" is NULL, otherwise interpret
56 // "definition.default_cstr_value" as a string value that represents the default
57 // value.
58 if (definition.default_cstr_value)
Ed Masted78c9572014-04-20 00:31:37 +000059 m_value_sp.reset (new OptionValueBoolean(Args::StringToBoolean (definition.default_cstr_value, false, nullptr)));
Greg Clayton67cc0632012-08-22 17:17:09 +000060 else
61 m_value_sp.reset (new OptionValueBoolean(definition.default_uint_value != 0));
62 break;
Zachary Turner3e7442b2015-01-12 20:44:02 +000063
64 case OptionValue::eTypeChar:
65 m_value_sp.reset(new OptionValueChar(Args::StringToChar(definition.default_cstr_value, '\0', nullptr)));
66 break;
67
Greg Clayton67cc0632012-08-22 17:17:09 +000068 case OptionValue::eTypeDictionary:
69 // "definition.default_uint_value" is always a OptionValue::Type
70 m_value_sp.reset (new OptionValueDictionary(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));
71 break;
72
73 case OptionValue::eTypeEnum:
74 // "definition.default_uint_value" is the default enumeration value if
75 // "definition.default_cstr_value" is NULL, otherwise interpret
76 // "definition.default_cstr_value" as a string value that represents the default
77 // value.
78 {
79 OptionValueEnumeration *enum_value = new OptionValueEnumeration(definition.enum_values, definition.default_uint_value);
80 m_value_sp.reset (enum_value);
81 if (definition.default_cstr_value)
82 {
83 if (enum_value->SetValueFromCString(definition.default_cstr_value).Success())
84 {
85 enum_value->SetDefaultValue(enum_value->GetCurrentValue());
86 // Call Clear() since we don't want the value to appear as
87 // having been set since we called SetValueFromCString() above.
88 // Clear will set the current value to the default and clear
89 // the boolean that says that the value has been set.
90 enum_value->Clear();
91 }
92 }
93 }
94 break;
95
96 case OptionValue::eTypeFileSpec:
97 // "definition.default_uint_value" represents if the "definition.default_cstr_value" should
98 // be resolved or not
99 m_value_sp.reset (new OptionValueFileSpec(FileSpec(definition.default_cstr_value, definition.default_uint_value != 0)));
100 break;
101
102 case OptionValue::eTypeFileSpecList:
103 // "definition.default_uint_value" is not used for a OptionValue::eTypeFileSpecList
104 m_value_sp.reset (new OptionValueFileSpecList());
105 break;
106
107 case OptionValue::eTypeFormat:
108 // "definition.default_uint_value" is the default format enumeration value if
109 // "definition.default_cstr_value" is NULL, otherwise interpret
110 // "definition.default_cstr_value" as a string value that represents the default
111 // value.
Greg Clayton554f68d2015-02-04 22:00:53 +0000112 {
113 Format new_format = eFormatInvalid;
114 if (definition.default_cstr_value)
115 Args::StringToFormat (definition.default_cstr_value, new_format, nullptr);
116 else
117 new_format = (Format)definition.default_uint_value;
118 m_value_sp.reset (new OptionValueFormat(new_format));
119 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000120 break;
121
Greg Clayton554f68d2015-02-04 22:00:53 +0000122 case OptionValue::eTypeFormatEntity:
123 // "definition.default_cstr_value" as a string value that represents the default
124 m_value_sp.reset (new OptionValueFormatEntity(definition.default_cstr_value));
125 break;
126
Greg Clayton67cc0632012-08-22 17:17:09 +0000127 case OptionValue::eTypePathMap:
128 // "definition.default_uint_value" tells us if notifications should occur for
129 // path mappings
130 m_value_sp.reset (new OptionValuePathMappings(definition.default_uint_value != 0));
131 break;
132
133 case OptionValue::eTypeRegex:
134 // "definition.default_uint_value" is used to the regular expression flags
135 // "definition.default_cstr_value" the default regular expression value
136 // value.
Greg Clayton7bd4c602015-01-21 21:51:02 +0000137 m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000138 break;
139
140 case OptionValue::eTypeSInt64:
141 // "definition.default_uint_value" is the default integer value if
142 // "definition.default_cstr_value" is NULL, otherwise interpret
143 // "definition.default_cstr_value" as a string value that represents the default
144 // value.
Vince Harron5275aaa2015-01-15 20:08:35 +0000145 m_value_sp.reset (new OptionValueSInt64(definition.default_cstr_value ? StringConvert::ToSInt64 (definition.default_cstr_value) : definition.default_uint_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000146 break;
147
148 case OptionValue::eTypeUInt64:
149 // "definition.default_uint_value" is the default unsigned integer value if
150 // "definition.default_cstr_value" is NULL, otherwise interpret
151 // "definition.default_cstr_value" as a string value that represents the default
152 // value.
Vince Harron5275aaa2015-01-15 20:08:35 +0000153 m_value_sp.reset (new OptionValueUInt64(definition.default_cstr_value ? StringConvert::ToUInt64 (definition.default_cstr_value) : definition.default_uint_value));
Greg Clayton67cc0632012-08-22 17:17:09 +0000154 break;
155
156 case OptionValue::eTypeUUID:
157 // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
158 // "definition.default_cstr_value" can contain a default UUID value
Greg Clayton554f68d2015-02-04 22:00:53 +0000159 {
160 UUID uuid;
161 if (definition.default_cstr_value)
162 uuid.SetFromCString (definition.default_cstr_value);
163 m_value_sp.reset (new OptionValueUUID(uuid));
164 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000165 break;
166
167 case OptionValue::eTypeString:
Greg Clayton4c054102012-09-01 00:38:36 +0000168 // "definition.default_uint_value" can contain the string option flags OR'ed together
Greg Clayton67cc0632012-08-22 17:17:09 +0000169 // "definition.default_cstr_value" can contain a default string value
Greg Clayton4c054102012-09-01 00:38:36 +0000170 {
171 OptionValueString *string_value = new OptionValueString(definition.default_cstr_value);
172 if (definition.default_uint_value != 0)
173 string_value->GetOptions().Reset(definition.default_uint_value);
174 m_value_sp.reset (string_value);
175 }
Greg Clayton67cc0632012-08-22 17:17:09 +0000176 break;
177 }
178}
179
180Property::Property (const ConstString &name,
181 const ConstString &desc,
182 bool is_global,
183 const lldb::OptionValueSP &value_sp) :
184 m_name (name),
185 m_description (desc),
186 m_value_sp (value_sp),
187 m_is_global (is_global)
188{
189}
190
191bool
192Property::DumpQualifiedName(Stream &strm) const
193{
194 if (m_name)
195 {
196 if (m_value_sp->DumpQualifiedName(strm))
197 strm.PutChar('.');
198 strm << m_name;
199 return true;
200 }
201 return false;
202}
203
204
205void
206Property::Dump (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const
207{
208 if (m_value_sp)
209 {
210 const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription;
211 const bool transparent = m_value_sp->ValueIsTransparent ();
212 if (dump_desc || !transparent)
213 {
214 if ((dump_mask & OptionValue::eDumpOptionName) && m_name)
215 {
216 DumpQualifiedName(strm);
217 if (dump_mask & ~OptionValue::eDumpOptionName)
218 strm.PutChar(' ');
219 }
220 }
221 if (dump_desc)
222 {
223 const char *desc = GetDescription();
224 if (desc)
225 strm.Printf ("-- %s", desc);
226
227 if (transparent && (dump_mask == (OptionValue::eDumpOptionName | OptionValue::eDumpOptionDescription)))
228 strm.EOL();
229 }
230 m_value_sp->DumpValue(exe_ctx, strm, dump_mask);
231 }
232}
233
234
235void
236Property::DumpDescription (CommandInterpreter &interpreter,
237 Stream &strm,
238 uint32_t output_width,
239 bool display_qualified_name) const
240{
241 if (m_value_sp)
242 {
243 const char *desc = GetDescription();
244
245 if (desc)
246 {
247 StreamString qualified_name;
248 const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties();
249 if (sub_properties)
250 {
251 strm.EOL();
252
253 if (m_value_sp->DumpQualifiedName(qualified_name))
254 strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str());
255 sub_properties->DumpAllDescriptions(interpreter, strm);
256 }
257 else
258 {
259 if (desc)
260 {
261 if (display_qualified_name)
262 {
263 StreamString qualified_name;
264 DumpQualifiedName(qualified_name);
265 interpreter.OutputFormattedHelpText (strm,
266 qualified_name.GetString().c_str(),
267 "--",
268 desc,
269 output_width);
270 }
271 else
272 {
273 interpreter.OutputFormattedHelpText (strm,
274 m_name.GetCString(),
275 "--",
276 desc,
277 output_width);
278 }
279 }
280 }
281 }
282 }
283}
284
Greg Clayton332e8b12015-01-13 21:13:08 +0000285
286void
287Property::SetValueChangedCallback (OptionValueChangedCallback callback, void *baton)
288{
289 if (m_value_sp)
290 m_value_sp->SetValueChangedCallback (callback, baton);
291}
292
293