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