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