10b57cec5SDimitry Andric //===-- ValueObjectSyntheticFilter.h ----------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 95ffd83dbSDimitry Andric #ifndef LLDB_CORE_VALUEOBJECTSYNTHETICFILTER_H 105ffd83dbSDimitry Andric #define LLDB_CORE_VALUEOBJECTSYNTHETICFILTER_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "lldb/Core/ValueObject.h" 130b57cec5SDimitry Andric #include "lldb/Symbol/CompilerType.h" 140b57cec5SDimitry Andric #include "lldb/Utility/ConstString.h" 150b57cec5SDimitry Andric #include "lldb/lldb-defines.h" 160b57cec5SDimitry Andric #include "lldb/lldb-enumerations.h" 170b57cec5SDimitry Andric #include "lldb/lldb-forward.h" 180b57cec5SDimitry Andric #include "lldb/lldb-private-enumerations.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric #include <cstdint> 210b57cec5SDimitry Andric #include <memory> 22bdd1243dSDimitry Andric #include <optional> 230b57cec5SDimitry Andric 24fe6060f1SDimitry Andric #include <cstddef> 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric namespace lldb_private { 270b57cec5SDimitry Andric class Declaration; 280b57cec5SDimitry Andric class Status; 290b57cec5SDimitry Andric class SyntheticChildrenFrontEnd; 300b57cec5SDimitry Andric 31fe6060f1SDimitry Andric /// A ValueObject that obtains its children from some source other than 32fe6060f1SDimitry Andric /// real information. 33fe6060f1SDimitry Andric /// This is currently used to implement Python-based children and filters but 34fe6060f1SDimitry Andric /// you can bind it to any source of synthetic information and have it behave 35fe6060f1SDimitry Andric /// accordingly. 360b57cec5SDimitry Andric class ValueObjectSynthetic : public ValueObject { 370b57cec5SDimitry Andric public: 380b57cec5SDimitry Andric ~ValueObjectSynthetic() override; 390b57cec5SDimitry Andric 40bdd1243dSDimitry Andric std::optional<uint64_t> GetByteSize() override; 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric ConstString GetTypeName() override; 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric ConstString GetQualifiedTypeName() override; 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric ConstString GetDisplayTypeName() override; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric bool MightHaveChildren() override; 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric size_t CalculateNumChildren(uint32_t max) override; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric lldb::ValueType GetValueType() const override; 530b57cec5SDimitry Andric 5406c3fb27SDimitry Andric lldb::ValueObjectSP GetChildAtIndex(size_t idx, 5506c3fb27SDimitry Andric bool can_create = true) override; 560b57cec5SDimitry Andric 5706c3fb27SDimitry Andric lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, 5806c3fb27SDimitry Andric bool can_create = true) override; 590b57cec5SDimitry Andric 6006c3fb27SDimitry Andric size_t GetIndexOfChildWithName(llvm::StringRef name) override; 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric lldb::ValueObjectSP 630b57cec5SDimitry Andric GetDynamicValue(lldb::DynamicValueType valueType) override; 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric bool IsInScope() override; 660b57cec5SDimitry Andric HasSyntheticValue()670b57cec5SDimitry Andric bool HasSyntheticValue() override { return false; } 680b57cec5SDimitry Andric IsSynthetic()690b57cec5SDimitry Andric bool IsSynthetic() override { return true; } 700b57cec5SDimitry Andric CalculateSyntheticValue()715ffd83dbSDimitry Andric void CalculateSyntheticValue() override {} 720b57cec5SDimitry Andric IsDynamic()730b57cec5SDimitry Andric bool IsDynamic() override { 740b57cec5SDimitry Andric return ((m_parent != nullptr) ? m_parent->IsDynamic() : false); 750b57cec5SDimitry Andric } 760b57cec5SDimitry Andric GetStaticValue()770b57cec5SDimitry Andric lldb::ValueObjectSP GetStaticValue() override { 780b57cec5SDimitry Andric return ((m_parent != nullptr) ? m_parent->GetStaticValue() : GetSP()); 790b57cec5SDimitry Andric } 800b57cec5SDimitry Andric GetDynamicValueType()810b57cec5SDimitry Andric virtual lldb::DynamicValueType GetDynamicValueType() { 820b57cec5SDimitry Andric return ((m_parent != nullptr) ? m_parent->GetDynamicValueType() 830b57cec5SDimitry Andric : lldb::eNoDynamicValues); 840b57cec5SDimitry Andric } 850b57cec5SDimitry Andric GetVariable()8606c3fb27SDimitry Andric lldb::VariableSP GetVariable() override { 8706c3fb27SDimitry Andric return m_parent != nullptr ? m_parent->GetVariable() : nullptr; 8806c3fb27SDimitry Andric } 8906c3fb27SDimitry Andric GetParent()900b57cec5SDimitry Andric ValueObject *GetParent() override { 910b57cec5SDimitry Andric return ((m_parent != nullptr) ? m_parent->GetParent() : nullptr); 920b57cec5SDimitry Andric } 930b57cec5SDimitry Andric GetParent()940b57cec5SDimitry Andric const ValueObject *GetParent() const override { 950b57cec5SDimitry Andric return ((m_parent != nullptr) ? m_parent->GetParent() : nullptr); 960b57cec5SDimitry Andric } 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric lldb::ValueObjectSP GetNonSyntheticValue() override; 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric bool CanProvideValue() override; 1010b57cec5SDimitry Andric DoesProvideSyntheticValue()1020b57cec5SDimitry Andric bool DoesProvideSyntheticValue() override { 1030b57cec5SDimitry Andric return (UpdateValueIfNeeded(), m_provides_value == eLazyBoolYes); 1040b57cec5SDimitry Andric } 1050b57cec5SDimitry Andric GetIsConstant()1060b57cec5SDimitry Andric bool GetIsConstant() const override { return false; } 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andric bool SetValueFromCString(const char *value_str, Status &error) override; 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric void SetFormat(lldb::Format format) override; 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric lldb::LanguageType GetPreferredDisplayLanguage() override; 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric void SetPreferredDisplayLanguage(lldb::LanguageType); 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric bool IsSyntheticChildrenGenerated() override; 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric void SetSyntheticChildrenGenerated(bool b) override; 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andric bool GetDeclaration(Declaration &decl) override; 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric uint64_t GetLanguageFlags() override; 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric void SetLanguageFlags(uint64_t flags) override; 1250b57cec5SDimitry Andric 1260b57cec5SDimitry Andric protected: 1270b57cec5SDimitry Andric bool UpdateValue() override; 1280b57cec5SDimitry Andric CanUpdateWithInvalidExecutionContext()1290b57cec5SDimitry Andric LazyBool CanUpdateWithInvalidExecutionContext() override { 1300b57cec5SDimitry Andric return eLazyBoolYes; 1310b57cec5SDimitry Andric } 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric CompilerType GetCompilerTypeImpl() override; 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andric virtual void CreateSynthFilter(); 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andric // we need to hold on to the SyntheticChildren because someone might delete 1380b57cec5SDimitry Andric // the type binding while we are alive 1390b57cec5SDimitry Andric lldb::SyntheticChildrenSP m_synth_sp; 1400b57cec5SDimitry Andric std::unique_ptr<SyntheticChildrenFrontEnd> m_synth_filter_up; 1410b57cec5SDimitry Andric 142480093f4SDimitry Andric typedef std::map<uint32_t, ValueObject *> ByIndexMap; 143480093f4SDimitry Andric typedef std::map<const char *, uint32_t> NameToIndexMap; 144480093f4SDimitry Andric typedef std::vector<lldb::ValueObjectSP> SyntheticChildrenCache; 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andric typedef ByIndexMap::iterator ByIndexIterator; 1470b57cec5SDimitry Andric typedef NameToIndexMap::iterator NameToIndexIterator; 1480b57cec5SDimitry Andric 149480093f4SDimitry Andric std::mutex m_child_mutex; 150480093f4SDimitry Andric /// Guarded by m_child_mutex; 1510b57cec5SDimitry Andric ByIndexMap m_children_byindex; 152480093f4SDimitry Andric /// Guarded by m_child_mutex; 1530b57cec5SDimitry Andric NameToIndexMap m_name_toindex; 154480093f4SDimitry Andric /// Guarded by m_child_mutex; 155480093f4SDimitry Andric SyntheticChildrenCache m_synthetic_children_cache; 156480093f4SDimitry Andric 157fe6060f1SDimitry Andric // FIXME: use the ValueObject's ChildrenManager instead of a special purpose 158fe6060f1SDimitry Andric // solution. 159fe6060f1SDimitry Andric uint32_t m_synthetic_children_count; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric ConstString m_parent_type_name; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric LazyBool m_might_have_children; 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andric LazyBool m_provides_value; 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric private: 1680b57cec5SDimitry Andric friend class ValueObject; 1690b57cec5SDimitry Andric ValueObjectSynthetic(ValueObject &parent, lldb::SyntheticChildrenSP filter); 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric void CopyValueData(ValueObject *source); 1720b57cec5SDimitry Andric 1735ffd83dbSDimitry Andric ValueObjectSynthetic(const ValueObjectSynthetic &) = delete; 1745ffd83dbSDimitry Andric const ValueObjectSynthetic &operator=(const ValueObjectSynthetic &) = delete; 1750b57cec5SDimitry Andric }; 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric } // namespace lldb_private 1780b57cec5SDimitry Andric 1795ffd83dbSDimitry Andric #endif // LLDB_CORE_VALUEOBJECTSYNTHETICFILTER_H 180