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