1 //===-- ValueObjectSyntheticFilter.h ----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_CORE_VALUEOBJECTSYNTHETICFILTER_H
10 #define LLDB_CORE_VALUEOBJECTSYNTHETICFILTER_H
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"
25 namespace lldb_private {
28 class SyntheticChildrenFrontEnd;
30 /// A ValueObject that obtains its children from some source other than
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
35 class ValueObjectSynthetic : public ValueObject {
37 ~ValueObjectSynthetic() override;
39 llvm::Optional<uint64_t> GetByteSize() override;
41 ConstString GetTypeName() override;
43 ConstString GetQualifiedTypeName() override;
45 ConstString GetDisplayTypeName() override;
47 bool MightHaveChildren() override;
49 size_t CalculateNumChildren(uint32_t max) override;
51 lldb::ValueType GetValueType() const override;
53 lldb::ValueObjectSP GetChildAtIndex(size_t idx, bool can_create) override;
55 lldb::ValueObjectSP GetChildMemberWithName(ConstString name,
56 bool can_create) override;
58 size_t GetIndexOfChildWithName(ConstString name) override;
61 GetDynamicValue(lldb::DynamicValueType valueType) override;
63 bool IsInScope() override;
65 bool HasSyntheticValue() override { return false; }
67 bool IsSynthetic() override { return true; }
69 void CalculateSyntheticValue() override {}
71 bool IsDynamic() override {
72 return ((m_parent != nullptr) ? m_parent->IsDynamic() : false);
75 lldb::ValueObjectSP GetStaticValue() override {
76 return ((m_parent != nullptr) ? m_parent->GetStaticValue() : GetSP());
79 virtual lldb::DynamicValueType GetDynamicValueType() {
80 return ((m_parent != nullptr) ? m_parent->GetDynamicValueType()
81 : lldb::eNoDynamicValues);
84 ValueObject *GetParent() override {
85 return ((m_parent != nullptr) ? m_parent->GetParent() : nullptr);
88 const ValueObject *GetParent() const override {
89 return ((m_parent != nullptr) ? m_parent->GetParent() : nullptr);
92 lldb::ValueObjectSP GetNonSyntheticValue() override;
94 bool CanProvideValue() override;
96 bool DoesProvideSyntheticValue() override {
97 return (UpdateValueIfNeeded(), m_provides_value == eLazyBoolYes);
100 bool GetIsConstant() const override { return false; }
102 bool SetValueFromCString(const char *value_str, Status &error) override;
104 void SetFormat(lldb::Format format) override;
106 lldb::LanguageType GetPreferredDisplayLanguage() override;
108 void SetPreferredDisplayLanguage(lldb::LanguageType);
110 bool IsSyntheticChildrenGenerated() override;
112 void SetSyntheticChildrenGenerated(bool b) override;
114 bool GetDeclaration(Declaration &decl) override;
116 uint64_t GetLanguageFlags() override;
118 void SetLanguageFlags(uint64_t flags) override;
121 bool UpdateValue() override;
123 LazyBool CanUpdateWithInvalidExecutionContext() override {
127 CompilerType GetCompilerTypeImpl() override;
129 virtual void CreateSynthFilter();
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;
136 typedef std::map<uint32_t, ValueObject *> ByIndexMap;
137 typedef std::map<const char *, uint32_t> NameToIndexMap;
138 typedef std::vector<lldb::ValueObjectSP> SyntheticChildrenCache;
140 typedef ByIndexMap::iterator ByIndexIterator;
141 typedef NameToIndexMap::iterator NameToIndexIterator;
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;
151 // FIXME: use the ValueObject's ChildrenManager instead of a special purpose
153 uint32_t m_synthetic_children_count;
155 ConstString m_parent_type_name;
157 LazyBool m_might_have_children;
159 LazyBool m_provides_value;
162 friend class ValueObject;
163 ValueObjectSynthetic(ValueObject &parent, lldb::SyntheticChildrenSP filter);
165 void CopyValueData(ValueObject *source);
167 ValueObjectSynthetic(const ValueObjectSynthetic &) = delete;
168 const ValueObjectSynthetic &operator=(const ValueObjectSynthetic &) = delete;
171 } // namespace lldb_private
173 #endif // LLDB_CORE_VALUEOBJECTSYNTHETICFILTER_H