1 //===-- OptionValueProperties.h ---------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H 10 #define LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H 11 12 #include <vector> 13 14 #include "lldb/Core/FormatEntity.h" 15 #include "lldb/Core/UniqueCStringMap.h" 16 #include "lldb/Interpreter/OptionValue.h" 17 #include "lldb/Interpreter/Property.h" 18 #include "lldb/Utility/ConstString.h" 19 20 namespace lldb_private { 21 class Properties; 22 23 class OptionValueProperties 24 : public Cloneable<OptionValueProperties, OptionValue>, 25 public std::enable_shared_from_this<OptionValueProperties> { 26 public: 27 OptionValueProperties() = default; 28 29 OptionValueProperties(ConstString name); 30 31 ~OptionValueProperties() override = default; 32 33 Type GetType() const override { return eTypeProperties; } 34 35 void Clear() override; 36 37 static lldb::OptionValuePropertiesSP 38 CreateLocalCopy(const Properties &global_properties); 39 40 lldb::OptionValueSP 41 DeepCopy(const lldb::OptionValueSP &new_parent) const override; 42 43 Status 44 SetValueFromString(llvm::StringRef value, 45 VarSetOperationType op = eVarSetOperationAssign) override; 46 47 void DumpValue(const ExecutionContext *exe_ctx, Stream &strm, 48 uint32_t dump_mask) override; 49 50 llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override; 51 52 ConstString GetName() const override { return m_name; } 53 54 virtual Status DumpPropertyValue(const ExecutionContext *exe_ctx, 55 Stream &strm, llvm::StringRef property_path, 56 uint32_t dump_mask, bool is_json = false); 57 58 virtual void DumpAllDescriptions(CommandInterpreter &interpreter, 59 Stream &strm) const; 60 61 void Apropos(llvm::StringRef keyword, 62 std::vector<const Property *> &matching_properties) const; 63 64 void Initialize(const PropertyDefinitions &setting_definitions); 65 66 // bool 67 // GetQualifiedName (Stream &strm); 68 69 // Subclass specific functions 70 71 virtual size_t GetNumProperties() const; 72 73 // Get the index of a property given its exact name in this property 74 // collection, "name" can't be a path to a property path that refers to a 75 // property within a property 76 virtual uint32_t GetPropertyIndex(ConstString name) const; 77 78 // Get a property by exact name exists in this property collection, name can 79 // not be a path to a property path that refers to a property within a 80 // property 81 virtual const Property *GetProperty(const ExecutionContext *exe_ctx, 82 bool will_modify, 83 ConstString name) const; 84 85 virtual const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx, 86 bool will_modify, 87 uint32_t idx) const; 88 89 // Property can be be a property path like 90 // "target.process.extra-startup-command" 91 virtual const Property *GetPropertyAtPath(const ExecutionContext *exe_ctx, 92 bool will_modify, 93 llvm::StringRef property_path) const; 94 95 virtual lldb::OptionValueSP 96 GetPropertyValueAtIndex(const ExecutionContext *exe_ctx, bool will_modify, 97 uint32_t idx) const; 98 99 virtual lldb::OptionValueSP GetValueForKey(const ExecutionContext *exe_ctx, 100 ConstString key, 101 bool value_will_be_modified) const; 102 103 lldb::OptionValueSP GetSubValue(const ExecutionContext *exe_ctx, 104 llvm::StringRef name, 105 bool value_will_be_modified, 106 Status &error) const override; 107 108 Status SetSubValue(const ExecutionContext *exe_ctx, VarSetOperationType op, 109 llvm::StringRef path, llvm::StringRef value) override; 110 111 OptionValueArch * 112 GetPropertyAtIndexAsOptionValueArch(const ExecutionContext *exe_ctx, 113 uint32_t idx) const; 114 115 OptionValueLanguage * 116 GetPropertyAtIndexAsOptionValueLanguage(const ExecutionContext *exe_ctx, 117 uint32_t idx) const; 118 119 bool SetPropertyAtIndexAsLanguage(const ExecutionContext *exe_ctx, 120 uint32_t idx, lldb::LanguageType lang); 121 122 bool GetPropertyAtIndexAsArgs(const ExecutionContext *exe_ctx, uint32_t idx, 123 Args &args) const; 124 125 bool SetPropertyAtIndexFromArgs(const ExecutionContext *exe_ctx, uint32_t idx, 126 const Args &args); 127 128 bool GetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx, 129 uint32_t idx, bool fail_value) const; 130 131 bool SetPropertyAtIndexAsBoolean(const ExecutionContext *exe_ctx, 132 uint32_t idx, bool new_value); 133 134 OptionValueDictionary * 135 GetPropertyAtIndexAsOptionValueDictionary(const ExecutionContext *exe_ctx, 136 uint32_t idx) const; 137 138 int64_t GetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx, 139 uint32_t idx, 140 int64_t fail_value) const; 141 142 bool SetPropertyAtIndexAsEnumeration(const ExecutionContext *exe_ctx, 143 uint32_t idx, int64_t new_value); 144 145 const FormatEntity::Entry * 146 GetPropertyAtIndexAsFormatEntity(const ExecutionContext *exe_ctx, 147 uint32_t idx); 148 149 const RegularExpression * 150 GetPropertyAtIndexAsOptionValueRegex(const ExecutionContext *exe_ctx, 151 uint32_t idx) const; 152 153 OptionValueSInt64 * 154 GetPropertyAtIndexAsOptionValueSInt64(const ExecutionContext *exe_ctx, 155 uint32_t idx) const; 156 157 OptionValueUInt64 * 158 GetPropertyAtIndexAsOptionValueUInt64(const ExecutionContext *exe_ctx, 159 uint32_t idx) const; 160 161 int64_t GetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx, 162 uint32_t idx, int64_t fail_value) const; 163 164 bool SetPropertyAtIndexAsSInt64(const ExecutionContext *exe_ctx, uint32_t idx, 165 int64_t new_value); 166 167 uint64_t GetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx, 168 uint32_t idx, uint64_t fail_value) const; 169 170 bool SetPropertyAtIndexAsUInt64(const ExecutionContext *exe_ctx, uint32_t idx, 171 uint64_t new_value); 172 173 llvm::StringRef GetPropertyAtIndexAsString(const ExecutionContext *exe_ctx, 174 uint32_t idx, 175 llvm::StringRef fail_value) const; 176 177 bool SetPropertyAtIndexAsString(const ExecutionContext *exe_ctx, uint32_t idx, 178 llvm::StringRef new_value); 179 180 OptionValueString * 181 GetPropertyAtIndexAsOptionValueString(const ExecutionContext *exe_ctx, 182 bool will_modify, uint32_t idx) const; 183 184 OptionValueFileSpec * 185 GetPropertyAtIndexAsOptionValueFileSpec(const ExecutionContext *exe_ctx, 186 bool will_modify, uint32_t idx) const; 187 188 FileSpec GetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx, 189 uint32_t idx) const; 190 191 bool SetPropertyAtIndexAsFileSpec(const ExecutionContext *exe_ctx, 192 uint32_t idx, const FileSpec &file_spec); 193 194 OptionValuePathMappings *GetPropertyAtIndexAsOptionValuePathMappings( 195 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const; 196 197 OptionValueFileSpecList *GetPropertyAtIndexAsOptionValueFileSpecList( 198 const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const; 199 200 void AppendProperty(ConstString name, ConstString desc, 201 bool is_global, const lldb::OptionValueSP &value_sp); 202 203 lldb::OptionValuePropertiesSP GetSubProperty(const ExecutionContext *exe_ctx, 204 ConstString name); 205 206 void SetValueChangedCallback(uint32_t property_idx, 207 std::function<void()> callback); 208 209 protected: 210 Property *ProtectedGetPropertyAtIndex(uint32_t idx) { 211 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr); 212 } 213 214 const Property *ProtectedGetPropertyAtIndex(uint32_t idx) const { 215 return ((idx < m_properties.size()) ? &m_properties[idx] : nullptr); 216 } 217 218 typedef UniqueCStringMap<size_t> NameToIndex; 219 220 ConstString m_name; 221 std::vector<Property> m_properties; 222 NameToIndex m_name_to_index; 223 }; 224 225 } // namespace lldb_private 226 227 #endif // LLDB_INTERPRETER_OPTIONVALUEPROPERTIES_H 228