Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 12 | #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 Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame^] | 19 | #include "lldb/Host/StringConvert.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 21 | #include "lldb/Interpreter/OptionValues.h" |
| 22 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
| 26 | Property::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 Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 59 | m_value_sp.reset (new OptionValueBoolean(Args::StringToBoolean (definition.default_cstr_value, false, nullptr))); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 60 | else |
| 61 | m_value_sp.reset (new OptionValueBoolean(definition.default_uint_value != 0)); |
| 62 | break; |
Zachary Turner | 3e7442b | 2015-01-12 20:44:02 +0000 | [diff] [blame] | 63 | |
| 64 | case OptionValue::eTypeChar: |
| 65 | m_value_sp.reset(new OptionValueChar(Args::StringToChar(definition.default_cstr_value, '\0', nullptr))); |
| 66 | break; |
| 67 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 68 | 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. |
| 112 | { |
| 113 | Format new_format = eFormatInvalid; |
| 114 | if (definition.default_cstr_value) |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 115 | Args::StringToFormat (definition.default_cstr_value, new_format, nullptr); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 116 | else |
| 117 | new_format = (Format)definition.default_uint_value; |
| 118 | m_value_sp.reset (new OptionValueFormat(new_format)); |
| 119 | } |
| 120 | break; |
| 121 | |
| 122 | case OptionValue::eTypePathMap: |
| 123 | // "definition.default_uint_value" tells us if notifications should occur for |
| 124 | // path mappings |
| 125 | m_value_sp.reset (new OptionValuePathMappings(definition.default_uint_value != 0)); |
| 126 | break; |
| 127 | |
| 128 | case OptionValue::eTypeRegex: |
| 129 | // "definition.default_uint_value" is used to the regular expression flags |
| 130 | // "definition.default_cstr_value" the default regular expression value |
| 131 | // value. |
| 132 | m_value_sp.reset (new OptionValueRegex(definition.default_cstr_value, definition.default_uint_value)); |
| 133 | break; |
| 134 | |
| 135 | case OptionValue::eTypeSInt64: |
| 136 | // "definition.default_uint_value" is the default integer value if |
| 137 | // "definition.default_cstr_value" is NULL, otherwise interpret |
| 138 | // "definition.default_cstr_value" as a string value that represents the default |
| 139 | // value. |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame^] | 140 | m_value_sp.reset (new OptionValueSInt64(definition.default_cstr_value ? StringConvert::ToSInt64 (definition.default_cstr_value) : definition.default_uint_value)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 141 | break; |
| 142 | |
| 143 | case OptionValue::eTypeUInt64: |
| 144 | // "definition.default_uint_value" is the default unsigned integer value if |
| 145 | // "definition.default_cstr_value" is NULL, otherwise interpret |
| 146 | // "definition.default_cstr_value" as a string value that represents the default |
| 147 | // value. |
Vince Harron | 5275aaa | 2015-01-15 20:08:35 +0000 | [diff] [blame^] | 148 | m_value_sp.reset (new OptionValueUInt64(definition.default_cstr_value ? StringConvert::ToUInt64 (definition.default_cstr_value) : definition.default_uint_value)); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 149 | break; |
| 150 | |
| 151 | case OptionValue::eTypeUUID: |
| 152 | // "definition.default_uint_value" is not used for a OptionValue::eTypeUUID |
| 153 | // "definition.default_cstr_value" can contain a default UUID value |
| 154 | { |
| 155 | UUID uuid; |
| 156 | if (definition.default_cstr_value) |
Greg Clayton | b5f0fea | 2012-09-27 22:26:11 +0000 | [diff] [blame] | 157 | uuid.SetFromCString (definition.default_cstr_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 158 | m_value_sp.reset (new OptionValueUUID(uuid)); |
| 159 | } |
| 160 | break; |
| 161 | |
| 162 | case OptionValue::eTypeString: |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 163 | // "definition.default_uint_value" can contain the string option flags OR'ed together |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 164 | // "definition.default_cstr_value" can contain a default string value |
Greg Clayton | 4c05410 | 2012-09-01 00:38:36 +0000 | [diff] [blame] | 165 | { |
| 166 | OptionValueString *string_value = new OptionValueString(definition.default_cstr_value); |
| 167 | if (definition.default_uint_value != 0) |
| 168 | string_value->GetOptions().Reset(definition.default_uint_value); |
| 169 | m_value_sp.reset (string_value); |
| 170 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 171 | break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | Property::Property (const ConstString &name, |
| 176 | const ConstString &desc, |
| 177 | bool is_global, |
| 178 | const lldb::OptionValueSP &value_sp) : |
| 179 | m_name (name), |
| 180 | m_description (desc), |
| 181 | m_value_sp (value_sp), |
| 182 | m_is_global (is_global) |
| 183 | { |
| 184 | } |
| 185 | |
| 186 | bool |
| 187 | Property::DumpQualifiedName(Stream &strm) const |
| 188 | { |
| 189 | if (m_name) |
| 190 | { |
| 191 | if (m_value_sp->DumpQualifiedName(strm)) |
| 192 | strm.PutChar('.'); |
| 193 | strm << m_name; |
| 194 | return true; |
| 195 | } |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | void |
| 201 | Property::Dump (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) const |
| 202 | { |
| 203 | if (m_value_sp) |
| 204 | { |
| 205 | const bool dump_desc = dump_mask & OptionValue::eDumpOptionDescription; |
| 206 | const bool transparent = m_value_sp->ValueIsTransparent (); |
| 207 | if (dump_desc || !transparent) |
| 208 | { |
| 209 | if ((dump_mask & OptionValue::eDumpOptionName) && m_name) |
| 210 | { |
| 211 | DumpQualifiedName(strm); |
| 212 | if (dump_mask & ~OptionValue::eDumpOptionName) |
| 213 | strm.PutChar(' '); |
| 214 | } |
| 215 | } |
| 216 | if (dump_desc) |
| 217 | { |
| 218 | const char *desc = GetDescription(); |
| 219 | if (desc) |
| 220 | strm.Printf ("-- %s", desc); |
| 221 | |
| 222 | if (transparent && (dump_mask == (OptionValue::eDumpOptionName | OptionValue::eDumpOptionDescription))) |
| 223 | strm.EOL(); |
| 224 | } |
| 225 | m_value_sp->DumpValue(exe_ctx, strm, dump_mask); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | |
| 230 | void |
| 231 | Property::DumpDescription (CommandInterpreter &interpreter, |
| 232 | Stream &strm, |
| 233 | uint32_t output_width, |
| 234 | bool display_qualified_name) const |
| 235 | { |
| 236 | if (m_value_sp) |
| 237 | { |
| 238 | const char *desc = GetDescription(); |
| 239 | |
| 240 | if (desc) |
| 241 | { |
| 242 | StreamString qualified_name; |
| 243 | const OptionValueProperties *sub_properties = m_value_sp->GetAsProperties(); |
| 244 | if (sub_properties) |
| 245 | { |
| 246 | strm.EOL(); |
| 247 | |
| 248 | if (m_value_sp->DumpQualifiedName(qualified_name)) |
| 249 | strm.Printf("'%s' variables:\n\n", qualified_name.GetString().c_str()); |
| 250 | sub_properties->DumpAllDescriptions(interpreter, strm); |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | if (desc) |
| 255 | { |
| 256 | if (display_qualified_name) |
| 257 | { |
| 258 | StreamString qualified_name; |
| 259 | DumpQualifiedName(qualified_name); |
| 260 | interpreter.OutputFormattedHelpText (strm, |
| 261 | qualified_name.GetString().c_str(), |
| 262 | "--", |
| 263 | desc, |
| 264 | output_width); |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | interpreter.OutputFormattedHelpText (strm, |
| 269 | m_name.GetCString(), |
| 270 | "--", |
| 271 | desc, |
| 272 | output_width); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
Greg Clayton | 332e8b1 | 2015-01-13 21:13:08 +0000 | [diff] [blame] | 280 | |
| 281 | void |
| 282 | Property::SetValueChangedCallback (OptionValueChangedCallback callback, void *baton) |
| 283 | { |
| 284 | if (m_value_sp) |
| 285 | m_value_sp->SetValueChangedCallback (callback, baton); |
| 286 | } |
| 287 | |
| 288 | |