1 //===-- ValueObjectSyntheticFilter.h -------------------------------*- 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 #ifndef liblldb_ValueObjectSyntheticFilter_h_ 11 #define liblldb_ValueObjectSyntheticFilter_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <vector> 16 // Other libraries and framework includes 17 // Project includes 18 #include "lldb/Core/ThreadSafeSTLMap.h" 19 #include "lldb/Core/ValueObject.h" 20 21 namespace lldb_private { 22 23 //---------------------------------------------------------------------- 24 // A ValueObject that obtains its children from some source other than 25 // real information 26 // This is currently used to implement Python-based children and filters 27 // but you can bind it to any source of synthetic information and have 28 // it behave accordingly 29 //---------------------------------------------------------------------- 30 class ValueObjectSynthetic : public ValueObject 31 { 32 public: 33 virtual 34 ~ValueObjectSynthetic(); 35 36 virtual uint64_t 37 GetByteSize(); 38 39 virtual ConstString 40 GetTypeName(); 41 42 virtual ConstString 43 GetQualifiedTypeName(); 44 45 virtual ConstString 46 GetDisplayTypeName(); 47 48 virtual bool 49 MightHaveChildren(); 50 51 virtual size_t 52 CalculateNumChildren(); 53 54 virtual lldb::ValueType 55 GetValueType() const; 56 57 virtual lldb::ValueObjectSP 58 GetChildAtIndex (size_t idx, bool can_create); 59 60 virtual lldb::ValueObjectSP 61 GetChildMemberWithName (const ConstString &name, bool can_create); 62 63 virtual size_t 64 GetIndexOfChildWithName (const ConstString &name); 65 66 virtual lldb::ValueObjectSP 67 GetDynamicValue (lldb::DynamicValueType valueType); 68 69 virtual bool 70 IsInScope (); 71 72 virtual bool HasSyntheticValue()73 HasSyntheticValue() 74 { 75 return false; 76 } 77 78 virtual bool IsSynthetic()79 IsSynthetic() { return true; } 80 81 virtual void CalculateSyntheticValue(bool use_synthetic)82 CalculateSyntheticValue (bool use_synthetic) 83 { 84 } 85 86 virtual bool IsDynamic()87 IsDynamic () 88 { 89 if (m_parent) 90 return m_parent->IsDynamic(); 91 else 92 return false; 93 } 94 95 virtual lldb::ValueObjectSP GetStaticValue()96 GetStaticValue () 97 { 98 if (m_parent) 99 return m_parent->GetStaticValue(); 100 else 101 return GetSP(); 102 } 103 104 virtual lldb::DynamicValueType GetDynamicValueType()105 GetDynamicValueType () 106 { 107 if (m_parent) 108 return m_parent->GetDynamicValueType(); 109 else 110 return lldb::eNoDynamicValues; 111 } 112 113 virtual ValueObject * GetParent()114 GetParent() 115 { 116 if (m_parent) 117 return m_parent->GetParent(); 118 else 119 return NULL; 120 } 121 122 virtual const ValueObject * GetParent()123 GetParent() const 124 { 125 if (m_parent) 126 return m_parent->GetParent(); 127 else 128 return NULL; 129 } 130 131 virtual lldb::ValueObjectSP 132 GetNonSyntheticValue (); 133 134 virtual bool 135 CanProvideValue (); 136 137 virtual bool DoesProvideSyntheticValue()138 DoesProvideSyntheticValue () 139 { 140 return (UpdateValueIfNeeded(), m_provides_value == eLazyBoolYes); 141 } 142 143 virtual bool GetIsConstant()144 GetIsConstant () const 145 { 146 return false; 147 } 148 149 virtual bool 150 SetValueFromCString (const char *value_str, Error& error); 151 152 virtual void 153 SetFormat (lldb::Format format); 154 155 protected: 156 virtual bool 157 UpdateValue (); 158 159 virtual bool CanUpdateWithInvalidExecutionContext()160 CanUpdateWithInvalidExecutionContext () 161 { 162 return true; 163 } 164 165 virtual ClangASTType 166 GetClangTypeImpl (); 167 168 virtual void 169 CreateSynthFilter (); 170 171 // we need to hold on to the SyntheticChildren because someone might delete the type binding while we are alive 172 lldb::SyntheticChildrenSP m_synth_sp; 173 std::unique_ptr<SyntheticChildrenFrontEnd> m_synth_filter_ap; 174 175 typedef ThreadSafeSTLMap<uint32_t, ValueObject*> ByIndexMap; 176 typedef ThreadSafeSTLMap<const char*, uint32_t> NameToIndexMap; 177 178 typedef ByIndexMap::iterator ByIndexIterator; 179 typedef NameToIndexMap::iterator NameToIndexIterator; 180 181 ByIndexMap m_children_byindex; 182 NameToIndexMap m_name_toindex; 183 uint32_t m_synthetic_children_count; // FIXME use the ValueObject's ChildrenManager instead of a special purpose solution 184 185 ConstString m_parent_type_name; 186 187 LazyBool m_might_have_children; 188 189 LazyBool m_provides_value; 190 191 private: 192 friend class ValueObject; 193 ValueObjectSynthetic (ValueObject &parent, lldb::SyntheticChildrenSP filter); 194 195 void 196 CopyValueData (ValueObject *source); 197 198 //------------------------------------------------------------------ 199 // For ValueObject only 200 //------------------------------------------------------------------ 201 DISALLOW_COPY_AND_ASSIGN (ValueObjectSynthetic); 202 }; 203 204 } // namespace lldb_private 205 206 #endif // liblldb_ValueObjectSyntheticFilter_h_ 207