Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 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 <string.h> |
| 11 | #include <algorithm> |
| 12 | |
| 13 | #include "lldb/Core/UserSettingsController.h" |
| 14 | #include "lldb/Core/Error.h" |
Greg Clayton | 6ad07dd | 2010-12-19 03:41:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/RegularExpression.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Stream.h" |
| 17 | #include "lldb/Core/StreamString.h" |
| 18 | #include "lldb/Interpreter/CommandInterpreter.h" |
Zachary Turner | 633a29c | 2015-03-04 01:58:01 +0000 | [diff] [blame] | 19 | #include "lldb/Interpreter/OptionValueProperties.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 20 | #include "lldb/Interpreter/OptionValueString.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 21 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 22 | using namespace lldb; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 23 | using namespace lldb_private; |
| 24 | |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 25 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 26 | lldb::OptionValueSP |
| 27 | Properties::GetPropertyValue (const ExecutionContext *exe_ctx, |
| 28 | const char *path, |
| 29 | bool will_modify, |
| 30 | Error &error) const |
| 31 | { |
| 32 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 33 | if (properties_sp) |
| 34 | return properties_sp->GetSubValue(exe_ctx, path, will_modify, error); |
| 35 | return lldb::OptionValueSP(); |
Greg Clayton | bfe5f3b | 2011-02-18 01:44:25 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 38 | Error |
| 39 | Properties::SetPropertyValue (const ExecutionContext *exe_ctx, |
| 40 | VarSetOperationType op, |
| 41 | const char *path, |
| 42 | const char *value) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 43 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 44 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 45 | if (properties_sp) |
| 46 | return properties_sp->SetSubValue(exe_ctx, op, path, value); |
| 47 | Error error; |
| 48 | error.SetErrorString ("no properties"); |
| 49 | return error; |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 53 | Properties::DumpAllPropertyValues (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 54 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 55 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 56 | if (properties_sp) |
| 57 | return properties_sp->DumpValue (exe_ctx, strm, dump_mask); |
Jim Ingham | 9585275 | 2010-09-07 20:27:09 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 60 | void |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 61 | Properties::DumpAllDescriptions (CommandInterpreter &interpreter, |
| 62 | Stream &strm) const |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 63 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 64 | strm.PutCString("Top level variables:\n\n"); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 65 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 66 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 67 | if (properties_sp) |
| 68 | return properties_sp->DumpAllDescriptions (interpreter, strm); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | |
| 73 | Error |
| 74 | Properties::DumpPropertyValue (const ExecutionContext *exe_ctx, Stream &strm, const char *property_path, uint32_t dump_mask) |
| 75 | { |
| 76 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 77 | if (properties_sp) |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 78 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 79 | return properties_sp->DumpPropertyValue (exe_ctx, |
| 80 | strm, |
| 81 | property_path, |
| 82 | dump_mask); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 83 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 84 | Error error; |
| 85 | error.SetErrorString("empty property list"); |
| 86 | return error; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | size_t |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 90 | Properties::Apropos (const char *keyword, std::vector<const Property *> &matching_properties) const |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 91 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 92 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 93 | if (properties_sp) |
| 94 | { |
| 95 | properties_sp->Apropos (keyword, matching_properties); |
| 96 | } |
| 97 | return matching_properties.size(); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 98 | } |
Greg Clayton | e8cd0c9 | 2012-10-19 18:02:49 +0000 | [diff] [blame] | 99 | |
| 100 | |
| 101 | lldb::OptionValuePropertiesSP |
| 102 | Properties::GetSubProperty (const ExecutionContext *exe_ctx, |
| 103 | const ConstString &name) |
| 104 | { |
| 105 | OptionValuePropertiesSP properties_sp (GetValueProperties ()); |
| 106 | if (properties_sp) |
| 107 | return properties_sp->GetSubProperty (exe_ctx, name); |
| 108 | return lldb::OptionValuePropertiesSP(); |
| 109 | } |
| 110 | |
Jim Ingham | 8b57dcf | 2016-07-06 01:27:33 +0000 | [diff] [blame^] | 111 | const char * |
| 112 | Properties::GetExperimentalSettingsName() |
| 113 | { |
| 114 | return "experimental"; |
| 115 | } |
| 116 | |
| 117 | bool |
| 118 | Properties::IsSettingExperimental(const char *setting) |
| 119 | { |
| 120 | if (setting == nullptr) |
| 121 | return false; |
| 122 | |
| 123 | const char *experimental = GetExperimentalSettingsName(); |
| 124 | char *dot_pos = strchr(setting, '.'); |
| 125 | if (dot_pos == nullptr) |
| 126 | return strcmp(experimental, setting) == 0; |
| 127 | else |
| 128 | { |
| 129 | size_t first_elem_len = dot_pos - setting; |
| 130 | return strncmp(experimental, setting, first_elem_len) == 0; |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | |