OptionValueProperties.cpp revision 263363
1178825Sdfr//===-- OptionValueProperties.cpp ---------------------------------*- C++ -*-===// 2233294Sstas// 3233294Sstas// The LLVM Compiler Infrastructure 4233294Sstas// 5178825Sdfr// This file is distributed under the University of Illinois Open Source 6233294Sstas// License. See LICENSE.TXT for details. 7233294Sstas// 8233294Sstas//===----------------------------------------------------------------------===// 9178825Sdfr 10233294Sstas#include "lldb/Interpreter/OptionValueProperties.h" 11233294Sstas 12178825Sdfr// C Includes 13233294Sstas// C++ Includes 14233294Sstas// Other libraries and framework includes 15233294Sstas// Project includes 16178825Sdfr#include "lldb/Core/Flags.h" 17233294Sstas#include "lldb/Core/Stream.h" 18233294Sstas#include "lldb/Core/StringList.h" 19233294Sstas#include "lldb/Core/UserSettingsController.h" 20178825Sdfr#include "lldb/Interpreter/Args.h" 21233294Sstas#include "lldb/Interpreter/OptionValues.h" 22233294Sstas#include "lldb/Interpreter/Property.h" 23233294Sstas 24233294Sstasusing namespace lldb; 25233294Sstasusing namespace lldb_private; 26233294Sstas 27233294Sstas 28233294SstasOptionValueProperties::OptionValueProperties (const ConstString &name) : 29233294Sstas OptionValue (), 30233294Sstas m_name (name), 31233294Sstas m_properties (), 32178825Sdfr m_name_to_index () 33178825Sdfr{ 34178825Sdfr} 35178825Sdfr 36178825SdfrOptionValueProperties::OptionValueProperties (const OptionValueProperties &global_properties) : 37178825Sdfr OptionValue (global_properties), 38178825Sdfr m_name (global_properties.m_name), 39178825Sdfr m_properties (global_properties.m_properties), 40178825Sdfr m_name_to_index (global_properties.m_name_to_index) 41178825Sdfr{ 42178825Sdfr // We now have an exact copy of "global_properties". We need to now 43178825Sdfr // find all non-global settings and copy the property values so that 44178825Sdfr // all non-global settings get new OptionValue instances created for 45178825Sdfr // them. 46178825Sdfr const size_t num_properties = m_properties.size(); 47178825Sdfr for (size_t i=0; i<num_properties; ++i) 48178825Sdfr { 49178825Sdfr // Duplicate any values that are not global when contructing properties from 50178825Sdfr // a global copy 51178825Sdfr if (m_properties[i].IsGlobal() == false) 52178825Sdfr { 53178825Sdfr lldb::OptionValueSP new_value_sp (m_properties[i].GetValue()->DeepCopy()); 54178825Sdfr m_properties[i].SetOptionValue(new_value_sp); 55178825Sdfr } 56233294Sstas } 57178825Sdfr} 58178825Sdfr 59178825Sdfr 60178825Sdfr 61178825Sdfrsize_t 62233294SstasOptionValueProperties::GetNumProperties() const 63233294Sstas{ 64233294Sstas return m_properties.size(); 65178825Sdfr} 66178825Sdfr 67178825Sdfr 68178825Sdfrvoid 69178825SdfrOptionValueProperties::Initialize (const PropertyDefinition *defs) 70178825Sdfr{ 71178825Sdfr for (size_t i=0; defs[i].name; ++i) 72178825Sdfr { 73178825Sdfr Property property(defs[i]); 74178825Sdfr assert(property.IsValid()); 75178825Sdfr m_name_to_index.Append(property.GetName().GetCString(),m_properties.size()); 76178825Sdfr property.GetValue()->SetParent(shared_from_this()); 77178825Sdfr m_properties.push_back(property); 78178825Sdfr } 79178825Sdfr m_name_to_index.Sort(); 80178825Sdfr} 81178825Sdfr 82178825Sdfrvoid 83178825SdfrOptionValueProperties::AppendProperty(const ConstString &name, 84178825Sdfr const ConstString &desc, 85178825Sdfr bool is_global, 86178825Sdfr const OptionValueSP &value_sp) 87178825Sdfr{ 88178825Sdfr Property property(name, desc, is_global, value_sp); 89178825Sdfr m_name_to_index.Append(name.GetCString(),m_properties.size()); 90178825Sdfr m_properties.push_back(property); 91178825Sdfr value_sp->SetParent (shared_from_this()); 92178825Sdfr m_name_to_index.Sort(); 93178825Sdfr} 94178825Sdfr 95178825Sdfr 96178825Sdfr 97178825Sdfr//bool 98178825Sdfr//OptionValueProperties::GetQualifiedName (Stream &strm) 99178825Sdfr//{ 100178825Sdfr// bool dumped_something = false; 101178825Sdfr//// lldb::OptionValuePropertiesSP parent_sp(GetParent ()); 102178825Sdfr//// if (parent_sp) 103178825Sdfr//// { 104178825Sdfr//// parent_sp->GetQualifiedName (strm); 105178825Sdfr//// strm.PutChar('.'); 106178825Sdfr//// dumped_something = true; 107178825Sdfr//// } 108178825Sdfr// if (m_name) 109233294Sstas// { 110233294Sstas// strm << m_name; 111178825Sdfr// dumped_something = true; 112178825Sdfr// } 113178825Sdfr// return dumped_something; 114178825Sdfr//} 115178825Sdfr// 116178825Sdfrlldb::OptionValueSP 117178825SdfrOptionValueProperties::GetValueForKey (const ExecutionContext *exe_ctx, 118178825Sdfr const ConstString &key, 119178825Sdfr bool will_modify) const 120178825Sdfr{ 121178825Sdfr lldb::OptionValueSP value_sp; 122178825Sdfr size_t idx = m_name_to_index.Find (key.GetCString(), SIZE_MAX); 123178825Sdfr if (idx < m_properties.size()) 124178825Sdfr value_sp = GetPropertyAtIndex(exe_ctx, will_modify, idx)->GetValue(); 125178825Sdfr return value_sp; 126178825Sdfr} 127178825Sdfr 128178825Sdfrlldb::OptionValueSP 129178825SdfrOptionValueProperties::GetSubValue (const ExecutionContext *exe_ctx, 130178825Sdfr const char *name, 131178825Sdfr bool will_modify, 132178825Sdfr Error &error) const 133178825Sdfr{ 134178825Sdfr lldb::OptionValueSP value_sp; 135178825Sdfr 136178825Sdfr if (name && name[0]) 137178825Sdfr { 138178825Sdfr const char *sub_name = NULL; 139178825Sdfr ConstString key; 140178825Sdfr size_t key_len = ::strcspn (name, ".[{"); 141178825Sdfr 142178825Sdfr if (name[key_len]) 143178825Sdfr { 144178825Sdfr key.SetCStringWithLength (name, key_len); 145178825Sdfr sub_name = name + key_len; 146178825Sdfr } 147178825Sdfr else 148178825Sdfr key.SetCString (name); 149178825Sdfr 150178825Sdfr value_sp = GetValueForKey (exe_ctx, key, will_modify); 151178825Sdfr if (sub_name && value_sp) 152178825Sdfr { 153178825Sdfr switch (sub_name[0]) 154178825Sdfr { 155178825Sdfr case '.': 156178825Sdfr return value_sp->GetSubValue (exe_ctx, sub_name + 1, will_modify, error); 157178825Sdfr 158178825Sdfr case '{': 159178825Sdfr // Predicate matching for predicates like 160178825Sdfr // "<setting-name>{<predicate>}" 161178825Sdfr // strings are parsed by the current OptionValueProperties subclass 162178825Sdfr // to mean whatever they want to. For instance a subclass of 163178825Sdfr // OptionValueProperties for a lldb_private::Target might implement: 164178825Sdfr // "target.run-args{arch==i386}" -- only set run args if the arch is i386 165178825Sdfr // "target.run-args{path=/tmp/a/b/c/a.out}" -- only set run args if the path matches 166178825Sdfr // "target.run-args{basename==test&&arch==x86_64}" -- only set run args if exectable basename is "test" and arch is "x86_64" 167178825Sdfr if (sub_name[1]) 168178825Sdfr { 169178825Sdfr const char *predicate_start = sub_name + 1; 170178825Sdfr const char *predicate_end = strchr(predicate_start, '}'); 171178825Sdfr if (predicate_end) 172178825Sdfr { 173178825Sdfr std::string predicate(predicate_start, predicate_end); 174178825Sdfr if (PredicateMatches(exe_ctx, predicate.c_str())) 175178825Sdfr { 176178825Sdfr if (predicate_end[1]) 177178825Sdfr { 178178825Sdfr // Still more subvalue string to evaluate 179178825Sdfr return value_sp->GetSubValue (exe_ctx, predicate_end + 1, will_modify, error); 180178825Sdfr } 181178825Sdfr else 182178825Sdfr { 183178825Sdfr // We have a match! 184178825Sdfr break; 185178825Sdfr } 186178825Sdfr } 187178825Sdfr } 188178825Sdfr } 189178825Sdfr // Predicate didn't match or wasn't correctly formed 190178825Sdfr value_sp.reset(); 191178825Sdfr break; 192178825Sdfr 193178825Sdfr case '[': 194178825Sdfr // Array or dictionary access for subvalues like: 195178825Sdfr // "[12]" -- access 12th array element 196178825Sdfr // "['hello']" -- dictionary access of key named hello 197178825Sdfr return value_sp->GetSubValue (exe_ctx, sub_name, will_modify, error); 198178825Sdfr 199178825Sdfr default: 200178825Sdfr value_sp.reset(); 201178825Sdfr break; 202178825Sdfr } 203178825Sdfr } 204178825Sdfr } 205178825Sdfr return value_sp; 206178825Sdfr} 207178825Sdfr 208178825SdfrError 209178825SdfrOptionValueProperties::SetSubValue (const ExecutionContext *exe_ctx, 210178825Sdfr VarSetOperationType op, 211178825Sdfr const char *name, 212178825Sdfr const char *value) 213178825Sdfr{ 214178825Sdfr Error error; 215178825Sdfr const bool will_modify = true; 216178825Sdfr lldb::OptionValueSP value_sp (GetSubValue (exe_ctx, name, will_modify, error)); 217178825Sdfr if (value_sp) 218178825Sdfr error = value_sp->SetValueFromCString(value, op); 219178825Sdfr else 220178825Sdfr { 221178825Sdfr if (error.AsCString() == NULL) 222178825Sdfr error.SetErrorStringWithFormat("invalid value path '%s'", name); 223178825Sdfr } 224178825Sdfr return error; 225178825Sdfr} 226178825Sdfr 227178825Sdfr 228178825SdfrConstString 229178825SdfrOptionValueProperties::GetPropertyNameAtIndex (uint32_t idx) const 230178825Sdfr{ 231178825Sdfr const Property *property = GetPropertyAtIndex(NULL, false, idx); 232178825Sdfr if (property) 233178825Sdfr return property->GetName(); 234233294Sstas return ConstString(); 235178825Sdfr 236178825Sdfr} 237178825Sdfr 238178825Sdfrconst char * 239178825SdfrOptionValueProperties::GetPropertyDescriptionAtIndex (uint32_t idx) const 240178825Sdfr{ 241178825Sdfr const Property *property = GetPropertyAtIndex(NULL, false, idx); 242178825Sdfr if (property) 243178825Sdfr return property->GetDescription(); 244233294Sstas return NULL; 245178825Sdfr} 246178825Sdfr 247178825Sdfruint32_t 248178825SdfrOptionValueProperties::GetPropertyIndex (const ConstString &name) const 249178825Sdfr{ 250178825Sdfr return m_name_to_index.Find (name.GetCString(), SIZE_MAX); 251178825Sdfr} 252178825Sdfr 253178825Sdfrconst Property * 254178825SdfrOptionValueProperties::GetProperty (const ExecutionContext *exe_ctx, bool will_modify, const ConstString &name) const 255178825Sdfr{ 256178825Sdfr return GetPropertyAtIndex (exe_ctx, will_modify, m_name_to_index.Find (name.GetCString(), SIZE_MAX)); 257178825Sdfr} 258178825Sdfr 259178825Sdfrconst Property * 260178825SdfrOptionValueProperties::GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 261178825Sdfr{ 262178825Sdfr return ProtectedGetPropertyAtIndex (idx); 263178825Sdfr} 264178825Sdfr 265178825Sdfrlldb::OptionValueSP 266178825SdfrOptionValueProperties::GetPropertyValueAtIndex (const ExecutionContext *exe_ctx, 267178825Sdfr bool will_modify, 268178825Sdfr uint32_t idx) const 269233294Sstas{ 270178825Sdfr const Property *setting = GetPropertyAtIndex (exe_ctx, will_modify, idx); 271178825Sdfr if (setting) 272178825Sdfr return setting->GetValue(); 273178825Sdfr return OptionValueSP(); 274178825Sdfr} 275178825Sdfr 276178825SdfrOptionValuePathMappings * 277178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValuePathMappings (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 278178825Sdfr{ 279178825Sdfr OptionValueSP value_sp(GetPropertyValueAtIndex (exe_ctx, will_modify, idx)); 280178825Sdfr if (value_sp) 281178825Sdfr return value_sp->GetAsPathMappings(); 282178825Sdfr return NULL; 283178825Sdfr} 284178825Sdfr 285178825SdfrOptionValueFileSpecList * 286178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpecList (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 287178825Sdfr{ 288178825Sdfr OptionValueSP value_sp(GetPropertyValueAtIndex (exe_ctx, will_modify, idx)); 289178825Sdfr if (value_sp) 290178825Sdfr return value_sp->GetAsFileSpecList(); 291178825Sdfr return NULL; 292178825Sdfr} 293178825Sdfr 294178825SdfrOptionValueArch * 295178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueArch (const ExecutionContext *exe_ctx, uint32_t idx) const 296178825Sdfr{ 297178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 298178825Sdfr if (property) 299178825Sdfr return property->GetValue()->GetAsArch(); 300178825Sdfr return NULL; 301178825Sdfr} 302178825Sdfr 303178825Sdfrbool 304178825SdfrOptionValueProperties::GetPropertyAtIndexAsArgs (const ExecutionContext *exe_ctx, uint32_t idx, Args &args) const 305178825Sdfr{ 306178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 307178825Sdfr if (property) 308178825Sdfr { 309178825Sdfr OptionValue *value = property->GetValue().get(); 310178825Sdfr if (value) 311178825Sdfr { 312178825Sdfr const OptionValueArray *array = value->GetAsArray(); 313178825Sdfr if (array) 314178825Sdfr return array->GetArgs(args); 315178825Sdfr else 316178825Sdfr { 317178825Sdfr const OptionValueDictionary *dict = value->GetAsDictionary(); 318178825Sdfr if (dict) 319178825Sdfr return dict->GetArgs(args); 320178825Sdfr } 321178825Sdfr } 322178825Sdfr } 323178825Sdfr return false; 324178825Sdfr} 325178825Sdfr 326178825Sdfrbool 327178825SdfrOptionValueProperties::SetPropertyAtIndexFromArgs (const ExecutionContext *exe_ctx, uint32_t idx, const Args &args) 328178825Sdfr{ 329178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 330178825Sdfr if (property) 331178825Sdfr { 332178825Sdfr OptionValue *value = property->GetValue().get(); 333178825Sdfr if (value) 334178825Sdfr { 335178825Sdfr OptionValueArray *array = value->GetAsArray(); 336178825Sdfr if (array) 337178825Sdfr return array->SetArgs(args, eVarSetOperationAssign).Success(); 338178825Sdfr else 339178825Sdfr { 340178825Sdfr OptionValueDictionary *dict = value->GetAsDictionary(); 341178825Sdfr if (dict) 342178825Sdfr return dict->SetArgs(args, eVarSetOperationAssign).Success(); 343178825Sdfr } 344178825Sdfr } 345178825Sdfr } 346178825Sdfr return false; 347178825Sdfr} 348178825Sdfr 349178825Sdfrbool 350178825SdfrOptionValueProperties::GetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool fail_value) const 351178825Sdfr{ 352178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 353178825Sdfr if (property) 354178825Sdfr { 355178825Sdfr OptionValue *value = property->GetValue().get(); 356178825Sdfr if (value) 357178825Sdfr return value->GetBooleanValue(fail_value); 358178825Sdfr } 359178825Sdfr return fail_value; 360178825Sdfr} 361178825Sdfr 362178825Sdfrbool 363178825SdfrOptionValueProperties::SetPropertyAtIndexAsBoolean (const ExecutionContext *exe_ctx, uint32_t idx, bool new_value) 364178825Sdfr{ 365178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 366178825Sdfr if (property) 367178825Sdfr { 368178825Sdfr OptionValue *value = property->GetValue().get(); 369178825Sdfr if (value) 370178825Sdfr { 371178825Sdfr value->SetBooleanValue(new_value); 372178825Sdfr return true; 373178825Sdfr } 374178825Sdfr } 375178825Sdfr return false; 376178825Sdfr} 377178825Sdfr 378178825SdfrOptionValueDictionary * 379178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueDictionary (const ExecutionContext *exe_ctx, uint32_t idx) const 380178825Sdfr{ 381178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 382178825Sdfr if (property) 383178825Sdfr return property->GetValue()->GetAsDictionary(); 384178825Sdfr return NULL; 385178825Sdfr} 386178825Sdfr 387178825Sdfrint64_t 388178825SdfrOptionValueProperties::GetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const 389178825Sdfr{ 390178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 391178825Sdfr if (property) 392178825Sdfr { 393178825Sdfr OptionValue *value = property->GetValue().get(); 394178825Sdfr if (value) 395178825Sdfr return value->GetEnumerationValue(fail_value); 396178825Sdfr } 397178825Sdfr return fail_value; 398178825Sdfr} 399178825Sdfr 400178825Sdfrbool 401178825SdfrOptionValueProperties::SetPropertyAtIndexAsEnumeration (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value) 402178825Sdfr{ 403178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 404178825Sdfr if (property) 405178825Sdfr { 406178825Sdfr OptionValue *value = property->GetValue().get(); 407178825Sdfr if (value) 408178825Sdfr return value->SetEnumerationValue(new_value); 409178825Sdfr } 410178825Sdfr return false; 411178825Sdfr} 412178825Sdfr 413178825Sdfr 414178825SdfrOptionValueFileSpec * 415178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueFileSpec (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 416178825Sdfr{ 417178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 418178825Sdfr if (property) 419178825Sdfr { 420178825Sdfr OptionValue *value = property->GetValue().get(); 421178825Sdfr if (value) 422178825Sdfr return value->GetAsFileSpec(); 423178825Sdfr } 424178825Sdfr return NULL; 425178825Sdfr} 426178825Sdfr 427178825Sdfr 428178825SdfrFileSpec 429178825SdfrOptionValueProperties::GetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx) const 430178825Sdfr{ 431178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 432178825Sdfr if (property) 433178825Sdfr { 434178825Sdfr OptionValue *value = property->GetValue().get(); 435178825Sdfr if (value) 436178825Sdfr return value->GetFileSpecValue(); 437178825Sdfr } 438178825Sdfr return FileSpec(); 439178825Sdfr} 440178825Sdfr 441178825Sdfr 442178825Sdfrbool 443178825SdfrOptionValueProperties::SetPropertyAtIndexAsFileSpec (const ExecutionContext *exe_ctx, uint32_t idx, const FileSpec &new_file_spec) 444178825Sdfr{ 445178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 446178825Sdfr if (property) 447178825Sdfr { 448178825Sdfr OptionValue *value = property->GetValue().get(); 449178825Sdfr if (value) 450178825Sdfr return value->SetFileSpecValue(new_file_spec); 451178825Sdfr } 452178825Sdfr return false; 453178825Sdfr} 454178825Sdfr 455178825Sdfrconst RegularExpression * 456178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueRegex (const ExecutionContext *exe_ctx, uint32_t idx) const 457178825Sdfr{ 458178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 459178825Sdfr if (property) 460178825Sdfr { 461178825Sdfr OptionValue *value = property->GetValue().get(); 462178825Sdfr if (value) 463178825Sdfr return value->GetRegexValue(); 464178825Sdfr } 465178825Sdfr return NULL; 466178825Sdfr} 467178825Sdfr 468178825SdfrOptionValueSInt64 * 469178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueSInt64 (const ExecutionContext *exe_ctx, uint32_t idx) const 470178825Sdfr{ 471233294Sstas const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 472178825Sdfr if (property) 473178825Sdfr { 474178825Sdfr OptionValue *value = property->GetValue().get(); 475178825Sdfr if (value) 476178825Sdfr return value->GetAsSInt64(); 477178825Sdfr } 478178825Sdfr return NULL; 479178825Sdfr} 480178825Sdfr 481178825Sdfrint64_t 482178825SdfrOptionValueProperties::GetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t fail_value) const 483178825Sdfr{ 484233294Sstas const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 485233294Sstas if (property) 486178825Sdfr { 487233294Sstas OptionValue *value = property->GetValue().get(); 488233294Sstas if (value) 489178825Sdfr return value->GetSInt64Value(fail_value); 490178825Sdfr } 491178825Sdfr return fail_value; 492178825Sdfr} 493178825Sdfr 494178825Sdfrbool 495178825SdfrOptionValueProperties::SetPropertyAtIndexAsSInt64 (const ExecutionContext *exe_ctx, uint32_t idx, int64_t new_value) 496178825Sdfr{ 497178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 498178825Sdfr if (property) 499178825Sdfr { 500178825Sdfr OptionValue *value = property->GetValue().get(); 501178825Sdfr if (value) 502178825Sdfr return value->SetSInt64Value(new_value); 503178825Sdfr } 504178825Sdfr return false; 505178825Sdfr} 506178825Sdfr 507178825Sdfrconst char * 508233294SstasOptionValueProperties::GetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *fail_value) const 509178825Sdfr{ 510178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 511178825Sdfr if (property) 512178825Sdfr { 513178825Sdfr OptionValue *value = property->GetValue().get(); 514178825Sdfr if (value) 515178825Sdfr return value->GetStringValue(fail_value); 516178825Sdfr } 517178825Sdfr return fail_value; 518178825Sdfr} 519178825Sdfr 520178825Sdfrbool 521178825SdfrOptionValueProperties::SetPropertyAtIndexAsString (const ExecutionContext *exe_ctx, uint32_t idx, const char *new_value) 522178825Sdfr{ 523178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 524178825Sdfr if (property) 525178825Sdfr { 526178825Sdfr OptionValue *value = property->GetValue().get(); 527178825Sdfr if (value) 528178825Sdfr return value->SetStringValue(new_value); 529178825Sdfr } 530178825Sdfr return false; 531178825Sdfr} 532178825Sdfr 533178825SdfrOptionValueString * 534178825SdfrOptionValueProperties::GetPropertyAtIndexAsOptionValueString (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 535178825Sdfr{ 536178825Sdfr OptionValueSP value_sp(GetPropertyValueAtIndex (exe_ctx, will_modify, idx)); 537178825Sdfr if (value_sp) 538178825Sdfr return value_sp->GetAsString(); 539178825Sdfr return NULL; 540178825Sdfr} 541178825Sdfr 542178825Sdfr 543178825Sdfruint64_t 544178825SdfrOptionValueProperties::GetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t fail_value) const 545178825Sdfr{ 546178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, false, idx); 547178825Sdfr if (property) 548178825Sdfr { 549178825Sdfr OptionValue *value = property->GetValue().get(); 550178825Sdfr if (value) 551178825Sdfr return value->GetUInt64Value(fail_value); 552178825Sdfr } 553178825Sdfr return fail_value; 554178825Sdfr} 555178825Sdfr 556178825Sdfrbool 557178825SdfrOptionValueProperties::SetPropertyAtIndexAsUInt64 (const ExecutionContext *exe_ctx, uint32_t idx, uint64_t new_value) 558178825Sdfr{ 559178825Sdfr const Property *property = GetPropertyAtIndex (exe_ctx, true, idx); 560178825Sdfr if (property) 561178825Sdfr { 562178825Sdfr OptionValue *value = property->GetValue().get(); 563178825Sdfr if (value) 564178825Sdfr return value->SetUInt64Value(new_value); 565178825Sdfr } 566178825Sdfr return false; 567178825Sdfr} 568178825Sdfr 569178825Sdfrbool 570178825SdfrOptionValueProperties::Clear () 571178825Sdfr{ 572178825Sdfr const size_t num_properties = m_properties.size(); 573178825Sdfr for (size_t i=0; i<num_properties; ++i) 574178825Sdfr m_properties[i].GetValue()->Clear(); 575178825Sdfr return true; 576178825Sdfr} 577178825Sdfr 578233294Sstas 579178825SdfrError 580178825SdfrOptionValueProperties::SetValueFromCString (const char *value, VarSetOperationType op) 581178825Sdfr{ 582178825Sdfr Error error; 583178825Sdfr 584178825Sdfr// Args args(value_cstr); 585178825Sdfr// const size_t argc = args.GetArgumentCount(); 586178825Sdfr switch (op) 587178825Sdfr { 588178825Sdfr case eVarSetOperationClear: 589178825Sdfr Clear (); 590178825Sdfr break; 591178825Sdfr 592178825Sdfr case eVarSetOperationReplace: 593178825Sdfr case eVarSetOperationAssign: 594178825Sdfr case eVarSetOperationRemove: 595178825Sdfr case eVarSetOperationInsertBefore: 596178825Sdfr case eVarSetOperationInsertAfter: 597178825Sdfr case eVarSetOperationAppend: 598178825Sdfr case eVarSetOperationInvalid: 599178825Sdfr error = OptionValue::SetValueFromCString (value, op); 600178825Sdfr break; 601178825Sdfr } 602178825Sdfr 603178825Sdfr return error; 604178825Sdfr} 605178825Sdfr 606178825Sdfrvoid 607178825SdfrOptionValueProperties::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 608178825Sdfr{ 609178825Sdfr const size_t num_properties = m_properties.size(); 610178825Sdfr for (size_t i=0; i<num_properties; ++i) 611178825Sdfr { 612178825Sdfr const Property *property = GetPropertyAtIndex(exe_ctx, false, i); 613233294Sstas if (property) 614178825Sdfr { 615178825Sdfr OptionValue *option_value = property->GetValue().get(); 616178825Sdfr assert (option_value); 617178825Sdfr const bool transparent_value = option_value->ValueIsTransparent (); 618178825Sdfr property->Dump (exe_ctx, 619178825Sdfr strm, 620233294Sstas dump_mask); 621178825Sdfr if (!transparent_value) 622178825Sdfr strm.EOL(); 623178825Sdfr } 624178825Sdfr } 625178825Sdfr} 626178825Sdfr 627178825SdfrError 628233294SstasOptionValueProperties::DumpPropertyValue (const ExecutionContext *exe_ctx, 629178825Sdfr Stream &strm, 630178825Sdfr const char *property_path, 631178825Sdfr uint32_t dump_mask) 632178825Sdfr{ 633178825Sdfr Error error; 634178825Sdfr const bool will_modify = false; 635178825Sdfr lldb::OptionValueSP value_sp (GetSubValue (exe_ctx, property_path, will_modify, error)); 636233294Sstas if (value_sp) 637178825Sdfr { 638178825Sdfr if (!value_sp->ValueIsTransparent ()) 639178825Sdfr { 640178825Sdfr if (dump_mask & eDumpOptionName) 641178825Sdfr strm.PutCString (property_path); 642178825Sdfr if (dump_mask & ~eDumpOptionName) 643178825Sdfr strm.PutChar (' '); 644178825Sdfr } 645178825Sdfr value_sp->DumpValue (exe_ctx, strm, dump_mask); 646178825Sdfr } 647178825Sdfr return error; 648178825Sdfr} 649178825Sdfr 650178825Sdfrlldb::OptionValueSP 651178825SdfrOptionValueProperties::DeepCopy () const 652178825Sdfr{ 653178825Sdfr assert(!"this shouldn't happen"); 654178825Sdfr return lldb::OptionValueSP(); 655178825Sdfr} 656178825Sdfr 657178825Sdfrconst Property * 658178825SdfrOptionValueProperties::GetPropertyAtPath (const ExecutionContext *exe_ctx, 659178825Sdfr bool will_modify, 660233294Sstas const char *name) const 661178825Sdfr{ 662178825Sdfr const Property *property = NULL; 663178825Sdfr if (name && name[0]) 664178825Sdfr { 665178825Sdfr const char *sub_name = NULL; 666178825Sdfr ConstString key; 667178825Sdfr size_t key_len = ::strcspn (name, ".[{"); 668233294Sstas 669178825Sdfr if (name[key_len]) 670178825Sdfr { 671233294Sstas key.SetCStringWithLength (name, key_len); 672178825Sdfr sub_name = name + key_len; 673178825Sdfr } 674178825Sdfr else 675178825Sdfr key.SetCString (name); 676178825Sdfr 677178825Sdfr property = GetProperty (exe_ctx, will_modify, key); 678178825Sdfr if (sub_name && property) 679178825Sdfr { 680178825Sdfr if (sub_name[0] == '.') 681233294Sstas { 682178825Sdfr OptionValueProperties *sub_properties = property->GetValue()->GetAsProperties(); 683178825Sdfr if (sub_properties) 684178825Sdfr return sub_properties->GetPropertyAtPath(exe_ctx, will_modify, sub_name + 1); 685178825Sdfr } 686178825Sdfr property = NULL; 687178825Sdfr } 688178825Sdfr } 689178825Sdfr return property; 690178825Sdfr} 691178825Sdfr 692233294Sstasvoid 693178825SdfrOptionValueProperties::DumpAllDescriptions (CommandInterpreter &interpreter, 694178825Sdfr Stream &strm) const 695178825Sdfr{ 696178825Sdfr size_t max_name_len = 0; 697178825Sdfr const size_t num_properties = m_properties.size(); 698178825Sdfr for (size_t i=0; i<num_properties; ++i) 699178825Sdfr { 700178825Sdfr const Property *property = ProtectedGetPropertyAtIndex(i); 701178825Sdfr if (property) 702178825Sdfr max_name_len = std::max<size_t>(property->GetName().GetLength(), max_name_len); 703178825Sdfr } 704178825Sdfr for (size_t i=0; i<num_properties; ++i) 705178825Sdfr { 706178825Sdfr const Property *property = ProtectedGetPropertyAtIndex(i); 707233294Sstas if (property) 708178825Sdfr property->DumpDescription (interpreter, strm, max_name_len, false); 709178825Sdfr } 710178825Sdfr} 711178825Sdfr 712178825Sdfrvoid 713178825SdfrOptionValueProperties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const 714178825Sdfr{ 715178825Sdfr const size_t num_properties = m_properties.size(); 716178825Sdfr StreamString strm; 717178825Sdfr for (size_t i=0; i<num_properties; ++i) 718178825Sdfr { 719178825Sdfr const Property *property = ProtectedGetPropertyAtIndex(i); 720178825Sdfr if (property) 721178825Sdfr { 722178825Sdfr const OptionValueProperties *properties = property->GetValue()->GetAsProperties(); 723178825Sdfr if (properties) 724178825Sdfr { 725178825Sdfr properties->Apropos (keyword, matching_properties); 726178825Sdfr } 727178825Sdfr else 728178825Sdfr { 729178825Sdfr bool match = false; 730178825Sdfr const char *name = property->GetName().GetCString(); 731178825Sdfr if (name && ::strcasestr(name, keyword)) 732178825Sdfr match = true; 733178825Sdfr else 734178825Sdfr { 735233294Sstas const char *desc = property->GetDescription(); 736178825Sdfr if (desc && ::strcasestr(desc, keyword)) 737178825Sdfr match = true; 738178825Sdfr } 739178825Sdfr if (match) 740178825Sdfr { 741178825Sdfr matching_properties.push_back (property); 742178825Sdfr } 743178825Sdfr } 744178825Sdfr } 745178825Sdfr } 746178825Sdfr} 747178825Sdfr 748178825Sdfrlldb::OptionValuePropertiesSP 749178825SdfrOptionValueProperties::GetSubProperty (const ExecutionContext *exe_ctx, 750178825Sdfr const ConstString &name) 751178825Sdfr{ 752178825Sdfr lldb::OptionValueSP option_value_sp(GetValueForKey(exe_ctx, name, false)); 753178825Sdfr if (option_value_sp) 754178825Sdfr { 755178825Sdfr OptionValueProperties *ov_properties = option_value_sp->GetAsProperties (); 756233294Sstas if (ov_properties) 757178825Sdfr return ov_properties->shared_from_this(); 758178825Sdfr } 759178825Sdfr return lldb::OptionValuePropertiesSP(); 760178825Sdfr} 761178825Sdfr 762178825Sdfr 763178825Sdfr 764178825Sdfr