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