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