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/UserSettingsController.h" 15 #include "lldb/Interpreter/CommandInterpreter.h" 16 #include "lldb/Interpreter/OptionValueProperties.h" 17 #include "lldb/Interpreter/OptionValueString.h" 18 #include "lldb/Utility/Error.h" 19 #include "lldb/Utility/RegularExpression.h" 20 #include "lldb/Utility/Stream.h" 21 #include "lldb/Utility/StreamString.h" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 lldb::OptionValueSP 27 Properties::GetPropertyValue(const ExecutionContext *exe_ctx, llvm::StringRef 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, llvm::StringRef path, 37 llvm::StringRef 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, llvm::StringRef 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(llvm::StringRef 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(llvm::StringRef setting) { 97 if (setting.empty()) 98 return false; 99 100 llvm::StringRef experimental = GetExperimentalSettingsName(); 101 size_t dot_pos = setting.find_first_of('.'); 102 return setting.take_front(dot_pos) == experimental; 103 } 104