180814287SRaphael Isemann //===-- LibCxxQueue.cpp ---------------------------------------------------===// 2e0d51846SPavel Labath // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e0d51846SPavel Labath // 7e0d51846SPavel Labath //===----------------------------------------------------------------------===// 8e0d51846SPavel Labath 9e0d51846SPavel Labath #include "LibCxx.h" 10e0d51846SPavel Labath #include "lldb/DataFormatters/FormattersHelpers.h" 11e0d51846SPavel Labath 12e0d51846SPavel Labath using namespace lldb; 13e0d51846SPavel Labath using namespace lldb_private; 14e0d51846SPavel Labath 15e0d51846SPavel Labath namespace { 16e0d51846SPavel Labath 17e0d51846SPavel Labath class QueueFrontEnd : public SyntheticChildrenFrontEnd { 18e0d51846SPavel Labath public: QueueFrontEnd(ValueObject & valobj)19e0d51846SPavel Labath QueueFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) { 20e0d51846SPavel Labath Update(); 21e0d51846SPavel Labath } 22e0d51846SPavel Labath GetIndexOfChildWithName(ConstString name)230e4c4821SAdrian Prantl size_t GetIndexOfChildWithName(ConstString name) override { 24e0d51846SPavel Labath return m_container_sp ? m_container_sp->GetIndexOfChildWithName(name) 25e0d51846SPavel Labath : UINT32_MAX; 26e0d51846SPavel Labath } 27e0d51846SPavel Labath MightHaveChildren()28e0d51846SPavel Labath bool MightHaveChildren() override { return true; } 29d7fb94b6SMichael Buch lldb::ChildCacheState Update() override; 30e0d51846SPavel Labath CalculateNumChildren()31*624ea68cSAdrian Prantl llvm::Expected<uint32_t> CalculateNumChildren() override { 32e0d51846SPavel Labath return m_container_sp ? m_container_sp->GetNumChildren() : 0; 33e0d51846SPavel Labath } 34e0d51846SPavel Labath GetChildAtIndex(uint32_t idx)35e710523eSAdrian Prantl ValueObjectSP GetChildAtIndex(uint32_t idx) override { 36a1a74f7cSDave Lee return m_container_sp ? m_container_sp->GetChildAtIndex(idx) 37e0d51846SPavel Labath : nullptr; 38e0d51846SPavel Labath } 39e0d51846SPavel Labath 40e0d51846SPavel Labath private: 4189386daaSCameron Desrochers // The lifetime of a ValueObject and all its derivative ValueObjects 4289386daaSCameron Desrochers // (children, clones, etc.) is managed by a ClusterManager. These 4389386daaSCameron Desrochers // objects are only destroyed when every shared pointer to any of them 4489386daaSCameron Desrochers // is destroyed, so we must not store a shared pointer to any ValueObject 4589386daaSCameron Desrochers // derived from our backend ValueObject (since we're in the same cluster). 4689386daaSCameron Desrochers ValueObject* m_container_sp = nullptr; 47e0d51846SPavel Labath }; 48e0d51846SPavel Labath } // namespace 49e0d51846SPavel Labath Update()50d7fb94b6SMichael Buchlldb::ChildCacheState QueueFrontEnd::Update() { 5189386daaSCameron Desrochers m_container_sp = nullptr; 527d4fcd41SDave Lee ValueObjectSP c_sp = m_backend.GetChildMemberWithName("c"); 53e0d51846SPavel Labath if (!c_sp) 54d7fb94b6SMichael Buch return lldb::ChildCacheState::eRefetch; 5589386daaSCameron Desrochers m_container_sp = c_sp->GetSyntheticValue().get(); 56d7fb94b6SMichael Buch return lldb::ChildCacheState::eRefetch; 57e0d51846SPavel Labath } 58e0d51846SPavel Labath 59e0d51846SPavel Labath SyntheticChildrenFrontEnd * LibcxxQueueFrontEndCreator(CXXSyntheticChildren *,lldb::ValueObjectSP valobj_sp)60e0d51846SPavel Labathformatters::LibcxxQueueFrontEndCreator(CXXSyntheticChildren *, 61e0d51846SPavel Labath lldb::ValueObjectSP valobj_sp) { 62e0d51846SPavel Labath if (valobj_sp) 63e0d51846SPavel Labath return new QueueFrontEnd(*valobj_sp); 64e0d51846SPavel Labath return nullptr; 65e0d51846SPavel Labath } 66