Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 1 | //====-- UserSettingsController.cpp ------------------------------*- C++-*-===// |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10 | #include "lldb/Core/UserSettingsController.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 11 | |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 12 | #include "lldb/Interpreter/OptionValueProperties.h" |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 13 | #include "lldb/Utility/Status.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 14 | #include "lldb/Utility/Stream.h" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 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 | } |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 30 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 31 | using namespace lldb; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 32 | using namespace lldb_private; |
| 33 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 34 | lldb::OptionValueSP |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 35 | Properties::GetPropertyValue(const ExecutionContext *exe_ctx, |
| 36 | llvm::StringRef path, bool will_modify, |
| 37 | Status &error) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 39 | if (properties_sp) |
| 40 | return properties_sp->GetSubValue(exe_ctx, path, will_modify, error); |
| 41 | return lldb::OptionValueSP(); |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 44 | Status Properties::SetPropertyValue(const ExecutionContext *exe_ctx, |
| 45 | VarSetOperationType op, |
| 46 | llvm::StringRef path, |
| 47 | llvm::StringRef value) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 49 | if (properties_sp) |
| 50 | return properties_sp->SetSubValue(exe_ctx, op, path, value); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 51 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | error.SetErrorString("no properties"); |
| 53 | return error; |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | void Properties::DumpAllPropertyValues(const ExecutionContext *exe_ctx, |
| 57 | Stream &strm, uint32_t dump_mask) { |
| 58 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 59 | if (properties_sp) |
| 60 | return properties_sp->DumpValue(exe_ctx, strm, dump_mask); |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | void Properties::DumpAllDescriptions(CommandInterpreter &interpreter, |
| 64 | Stream &strm) const { |
| 65 | strm.PutCString("Top level variables:\n\n"); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 68 | if (properties_sp) |
| 69 | return properties_sp->DumpAllDescriptions(interpreter, strm); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 72 | Status Properties::DumpPropertyValue(const ExecutionContext *exe_ctx, |
| 73 | Stream &strm, |
| 74 | llvm::StringRef property_path, |
| 75 | uint32_t dump_mask) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 77 | if (properties_sp) { |
| 78 | return properties_sp->DumpPropertyValue(exe_ctx, strm, property_path, |
| 79 | dump_mask); |
| 80 | } |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 81 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | error.SetErrorString("empty property list"); |
| 83 | return error; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | size_t |
Zachary Turner | 067d1db | 2016-11-16 21:45:04 +0000 | [diff] [blame] | 87 | Properties::Apropos(llvm::StringRef keyword, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | std::vector<const Property *> &matching_properties) const { |
| 89 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 90 | if (properties_sp) { |
| 91 | properties_sp->Apropos(keyword, matching_properties); |
| 92 | } |
| 93 | return matching_properties.size(); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 94 | } |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 95 | |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 96 | lldb::OptionValuePropertiesSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | Properties::GetSubProperty(const ExecutionContext *exe_ctx, |
| 98 | const ConstString &name) { |
| 99 | OptionValuePropertiesSP properties_sp(GetValueProperties()); |
| 100 | if (properties_sp) |
| 101 | return properties_sp->GetSubProperty(exe_ctx, name); |
| 102 | return lldb::OptionValuePropertiesSP(); |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | const char *Properties::GetExperimentalSettingsName() { return "experimental"; } |
| 106 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 107 | bool Properties::IsSettingExperimental(llvm::StringRef setting) { |
| 108 | if (setting.empty()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | return false; |
| 110 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 111 | llvm::StringRef experimental = GetExperimentalSettingsName(); |
| 112 | size_t dot_pos = setting.find_first_of('.'); |
| 113 | return setting.take_front(dot_pos) == experimental; |
Jim Ingham | 8b57dcf | 2016-07-06 01:27:33 +0000 | [diff] [blame] | 114 | } |