1 //====-- UserSettingsController.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 <string.h> 11 #include <algorithm> 12 13 #include "lldb/Core/UserSettingsController.h" 14 #include "lldb/Core/Error.h" 15 #include "lldb/Core/RegularExpression.h" 16 #include "lldb/Core/Stream.h" 17 #include "lldb/Core/StreamString.h" 18 #include "lldb/Interpreter/CommandInterpreter.h" 19 #include "lldb/Interpreter/OptionValueProperties.h" 20 #include "lldb/Interpreter/OptionValueString.h" 21 22 using namespace lldb; 23 using namespace lldb_private; 24 25 26 lldb::OptionValueSP 27 Properties::GetPropertyValue (const ExecutionContext *exe_ctx, 28 const char *path, 29 bool will_modify, 30 Error &error) const 31 { 32 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 33 if (properties_sp) 34 return properties_sp->GetSubValue(exe_ctx, path, will_modify, error); 35 return lldb::OptionValueSP(); 36 } 37 38 Error 39 Properties::SetPropertyValue (const ExecutionContext *exe_ctx, 40 VarSetOperationType op, 41 const char *path, 42 const char *value) 43 { 44 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 45 if (properties_sp) 46 return properties_sp->SetSubValue(exe_ctx, op, path, value); 47 Error error; 48 error.SetErrorString ("no properties"); 49 return error; 50 } 51 52 void 53 Properties::DumpAllPropertyValues (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 54 { 55 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 56 if (properties_sp) 57 return properties_sp->DumpValue (exe_ctx, strm, dump_mask); 58 } 59 60 void 61 Properties::DumpAllDescriptions (CommandInterpreter &interpreter, 62 Stream &strm) const 63 { 64 strm.PutCString("Top level variables:\n\n"); 65 66 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 67 if (properties_sp) 68 return properties_sp->DumpAllDescriptions (interpreter, strm); 69 } 70 71 72 73 Error 74 Properties::DumpPropertyValue (const ExecutionContext *exe_ctx, Stream &strm, const char *property_path, uint32_t dump_mask) 75 { 76 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 77 if (properties_sp) 78 { 79 return properties_sp->DumpPropertyValue (exe_ctx, 80 strm, 81 property_path, 82 dump_mask); 83 } 84 Error error; 85 error.SetErrorString("empty property list"); 86 return error; 87 } 88 89 size_t 90 Properties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const 91 { 92 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 93 if (properties_sp) 94 { 95 properties_sp->Apropos (keyword, matching_properties); 96 } 97 return matching_properties.size(); 98 } 99 100 101 lldb::OptionValuePropertiesSP 102 Properties::GetSubProperty (const ExecutionContext *exe_ctx, 103 const ConstString &name) 104 { 105 OptionValuePropertiesSP properties_sp (GetValueProperties ()); 106 if (properties_sp) 107 return properties_sp->GetSubProperty (exe_ctx, name); 108 return lldb::OptionValuePropertiesSP(); 109 } 110 111 const char * 112 Properties::GetExperimentalSettingsName() 113 { 114 return "experimental"; 115 } 116 117 bool 118 Properties::IsSettingExperimental(const char *setting) 119 { 120 if (setting == nullptr) 121 return false; 122 123 const char *experimental = GetExperimentalSettingsName(); 124 const char *dot_pos = strchr(setting, '.'); 125 if (dot_pos == nullptr) 126 return strcmp(experimental, setting) == 0; 127 else 128 { 129 size_t first_elem_len = dot_pos - setting; 130 return strncmp(experimental, setting, first_elem_len) == 0; 131 } 132 133 } 134 135