Author: jingham Date: Tue Jul 5 20:27:33 2016 New Revision: 274593 URL: http://llvm.org/viewvc/llvm-project?rev=274593&view=rev Log: Allows "experimental" settings that will either route to their containing settings or raise no error if not found.
From time to time it is useful to add some setting to work around or enable a transitory feature. We've been reluctant to remove them later because then we will break folks .lldbinit files. With this change you can add an "experimental" node to the settings. If you later decide you want to keep the option, just move it to the level that contained the "experimental" setting and it will still be found. Or just remove it - setting it will then silently fail and won't halt the .lldbinit file execution. Modified: lldb/trunk/include/lldb/Core/UserSettingsController.h lldb/trunk/source/Core/UserSettingsController.cpp lldb/trunk/source/Interpreter/OptionValueProperties.cpp Modified: lldb/trunk/include/lldb/Core/UserSettingsController.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/UserSettingsController.h?rev=274593&r1=274592&r2=274593&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/UserSettingsController.h (original) +++ lldb/trunk/include/lldb/Core/UserSettingsController.h Tue Jul 5 20:27:33 2016 @@ -88,6 +88,20 @@ public: lldb::OptionValuePropertiesSP GetSubProperty (const ExecutionContext *exe_ctx, const ConstString &name); + + // We sometimes need to introduce a setting to enable experimental features, + // but then we don't want the setting for these to cause errors when the setting + // goes away. Add a sub-topic of the settings using this experimental name, and + // two things will happen. One is that settings that don't find the name will not + // be treated as errors. Also, if you decide to keep the settings just move them into + // the containing properties, and we will auto-forward the experimental settings to the + // real one. + static const char * + GetExperimentalSettingsName(); + + static bool + IsSettingExperimental(const char *setting); + protected: lldb::OptionValuePropertiesSP m_collection_sp; }; Modified: lldb/trunk/source/Core/UserSettingsController.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserSettingsController.cpp?rev=274593&r1=274592&r2=274593&view=diff ============================================================================== --- lldb/trunk/source/Core/UserSettingsController.cpp (original) +++ lldb/trunk/source/Core/UserSettingsController.cpp Tue Jul 5 20:27:33 2016 @@ -108,3 +108,27 @@ Properties::GetSubProperty (const Execut return lldb::OptionValuePropertiesSP(); } +const char * +Properties::GetExperimentalSettingsName() +{ + return "experimental"; +} + +bool +Properties::IsSettingExperimental(const char *setting) +{ + if (setting == nullptr) + return false; + + const char *experimental = GetExperimentalSettingsName(); + char *dot_pos = strchr(setting, '.'); + if (dot_pos == nullptr) + return strcmp(experimental, setting) == 0; + else + { + size_t first_elem_len = dot_pos - setting; + return strncmp(experimental, setting, first_elem_len) == 0; + } + +} + Modified: lldb/trunk/source/Interpreter/OptionValueProperties.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueProperties.cpp?rev=274593&r1=274592&r2=274593&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/OptionValueProperties.cpp (original) +++ lldb/trunk/source/Interpreter/OptionValueProperties.cpp Tue Jul 5 20:27:33 2016 @@ -164,8 +164,23 @@ OptionValueProperties::GetSubValue (cons switch (sub_name[0]) { case '.': - return value_sp->GetSubValue (exe_ctx, sub_name + 1, will_modify, error); - + { + lldb::OptionValueSP return_val_sp; + return_val_sp = value_sp->GetSubValue (exe_ctx, sub_name + 1, will_modify, error); + if (!return_val_sp) + { + if (Properties::IsSettingExperimental(sub_name + 1)) + { + size_t experimental_len = strlen(Properties::GetExperimentalSettingsName()); + if (*(sub_name + experimental_len + 1) == '.') + return_val_sp = value_sp->GetSubValue(exe_ctx, sub_name + experimental_len + 2, will_modify, error); + // It isn't an error if an experimental setting is not present. + if (!return_val_sp) + error.Clear(); + } + } + return return_val_sp; + } case '{': // Predicate matching for predicates like // "<setting-name>{<predicate>}" _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits