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