15ffd83dbSDimitry Andric //===-- LibCxxQueue.cpp ---------------------------------------------------===// 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 90b57cec5SDimitry Andric #include "LibCxx.h" 100b57cec5SDimitry Andric #include "lldb/DataFormatters/FormattersHelpers.h" 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric using namespace lldb; 130b57cec5SDimitry Andric using namespace lldb_private; 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric namespace { 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric class QueueFrontEnd : public SyntheticChildrenFrontEnd { 180b57cec5SDimitry Andric public: 190b57cec5SDimitry Andric QueueFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) { 200b57cec5SDimitry Andric Update(); 210b57cec5SDimitry Andric } 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric size_t GetIndexOfChildWithName(ConstString name) override { 240b57cec5SDimitry Andric return m_container_sp ? m_container_sp->GetIndexOfChildWithName(name) 250b57cec5SDimitry Andric : UINT32_MAX; 260b57cec5SDimitry Andric } 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric bool MightHaveChildren() override { return true; } 29*0fca6ea1SDimitry Andric lldb::ChildCacheState Update() override; 300b57cec5SDimitry Andric 31*0fca6ea1SDimitry Andric llvm::Expected<uint32_t> CalculateNumChildren() override { 320b57cec5SDimitry Andric return m_container_sp ? m_container_sp->GetNumChildren() : 0; 330b57cec5SDimitry Andric } 340b57cec5SDimitry Andric 35*0fca6ea1SDimitry Andric ValueObjectSP GetChildAtIndex(uint32_t idx) override { 3606c3fb27SDimitry Andric return m_container_sp ? m_container_sp->GetChildAtIndex(idx) 370b57cec5SDimitry Andric : nullptr; 380b57cec5SDimitry Andric } 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric private: 419dba64beSDimitry Andric // The lifetime of a ValueObject and all its derivative ValueObjects 429dba64beSDimitry Andric // (children, clones, etc.) is managed by a ClusterManager. These 439dba64beSDimitry Andric // objects are only destroyed when every shared pointer to any of them 449dba64beSDimitry Andric // is destroyed, so we must not store a shared pointer to any ValueObject 459dba64beSDimitry Andric // derived from our backend ValueObject (since we're in the same cluster). 469dba64beSDimitry Andric ValueObject* m_container_sp = nullptr; 470b57cec5SDimitry Andric }; 480b57cec5SDimitry Andric } // namespace 490b57cec5SDimitry Andric 50*0fca6ea1SDimitry Andric lldb::ChildCacheState QueueFrontEnd::Update() { 519dba64beSDimitry Andric m_container_sp = nullptr; 5206c3fb27SDimitry Andric ValueObjectSP c_sp = m_backend.GetChildMemberWithName("c"); 530b57cec5SDimitry Andric if (!c_sp) 54*0fca6ea1SDimitry Andric return lldb::ChildCacheState::eRefetch; 559dba64beSDimitry Andric m_container_sp = c_sp->GetSyntheticValue().get(); 56*0fca6ea1SDimitry Andric return lldb::ChildCacheState::eRefetch; 570b57cec5SDimitry Andric } 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric SyntheticChildrenFrontEnd * 600b57cec5SDimitry Andric formatters::LibcxxQueueFrontEndCreator(CXXSyntheticChildren *, 610b57cec5SDimitry Andric lldb::ValueObjectSP valobj_sp) { 620b57cec5SDimitry Andric if (valobj_sp) 630b57cec5SDimitry Andric return new QueueFrontEnd(*valobj_sp); 640b57cec5SDimitry Andric return nullptr; 650b57cec5SDimitry Andric } 66