1 //====-- UserSettingsController.cpp ------------------------------*- C++ 2 //-*-===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is distributed under the University of Illinois Open Source 7 // License. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #include <algorithm> 12 #include <string.h> 13 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/Core/UserSettingsController.h" 19 #include "lldb/Interpreter/CommandInterpreter.h" 20 #include "lldb/Interpreter/OptionValueProperties.h" 21 #include "lldb/Interpreter/OptionValueString.h" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 lldb::OptionValueSP 27 Properties::GetPropertyValue(const ExecutionContext *exe_ctx, const char *path, 28 bool will_modify, Error &error) const { 29 OptionValuePropertiesSP properties_sp(GetValueProperties()); 30 if (properties_sp) 31 return properties_sp->GetSubValue(exe_ctx, path, will_modify, error); 32 return lldb::OptionValueSP(); 33 } 34 35 Error Properties::SetPropertyValue(const ExecutionContext *exe_ctx, 36 VarSetOperationType op, const char *path, 37 const char *value) { 38 OptionValuePropertiesSP properties_sp(GetValueProperties()); 39 if (properties_sp) 40 return properties_sp->SetSubValue(exe_ctx, op, path, value); 41 Error error; 42 error.SetErrorString("no properties"); 43 return error; 44 } 45 46 void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx, 47 Stream &strm, uint32_t dump_mask) { 48 OptionValuePropertiesSP properties_sp(GetValueProperties()); 49 if (properties_sp) 50 return properties_sp->DumpValue(exe_ctx, strm, dump_mask); 51 } 52 53 void Properties::DumpAllDescriptions(CommandInterpreter &interpreter, 54 Stream &strm) const { 55 strm.PutCString("Top level variables:\n\n"); 56 57 OptionValuePropertiesSP properties_sp(GetValueProperties()); 58 if (properties_sp) 59 return properties_sp->DumpAllDescriptions(interpreter, strm); 60 } 61 62 Error Properties::DumpPropertyValue(const ExecutionContext *exe_ctx, 63 Stream &strm, const char *property_path, 64 uint32_t dump_mask) { 65 OptionValuePropertiesSP properties_sp(GetValueProperties()); 66 if (properties_sp) { 67 return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path, 68 dump_mask); 69 } 70 Error error; 71 error.SetErrorString("empty property list"); 72 return error; 73 } 74 75 size_t 76 Properties::Apropos(const char *keyword, 77 std::vector<const Property *> &matching_properties) const { 78 OptionValuePropertiesSP properties_sp(GetValueProperties()); 79 if (properties_sp) { 80 properties_sp->Apropos(keyword, matching_properties); 81 } 82 return matching_properties.size(); 83 } 84 85 lldb::OptionValuePropertiesSP 86 Properties::GetSubProperty(const ExecutionContext *exe_ctx, 87 const ConstString &name) { 88 OptionValuePropertiesSP properties_sp(GetValueProperties()); 89 if (properties_sp) 90 return properties_sp->GetSubProperty(exe_ctx, name); 91 return lldb::OptionValuePropertiesSP(); 92 } 93 94 const char *Properties::GetExperimentalSettingsName() { return "experimental"; } 95 96 bool Properties::IsSettingExperimental(const char *setting) { 97 if (setting == nullptr) 98 return false; 99 100 const char *experimental = GetExperimentalSettingsName(); 101 const char *dot_pos = strchr(setting, '.'); 102 if (dot_pos == nullptr) 103 return strcmp(experimental, setting) == 0; 104 else { 105 size_t first_elem_len = dot_pos - setting; 106 return strncmp(experimental, setting, first_elem_len) == 0; 107 } 108 } 109