Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- LibCxxQueue.cpp ---------------------------------------------------===// |
Pavel Labath | e0d5184 | 2017-11-01 15:52:08 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Pavel Labath | e0d5184 | 2017-11-01 15:52:08 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "LibCxx.h" |
| 10 | #include "lldb/DataFormatters/FormattersHelpers.h" |
| 11 | |
| 12 | using namespace lldb; |
| 13 | using namespace lldb_private; |
| 14 | |
| 15 | namespace { |
| 16 | |
| 17 | class QueueFrontEnd : public SyntheticChildrenFrontEnd { |
| 18 | public: |
| 19 | QueueFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) { |
| 20 | Update(); |
| 21 | } |
| 22 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 23 | size_t GetIndexOfChildWithName(ConstString name) override { |
Pavel Labath | e0d5184 | 2017-11-01 15:52:08 +0000 | [diff] [blame] | 24 | return m_container_sp ? m_container_sp->GetIndexOfChildWithName(name) |
| 25 | : UINT32_MAX; |
| 26 | } |
| 27 | |
| 28 | bool MightHaveChildren() override { return true; } |
| 29 | bool Update() override; |
| 30 | |
| 31 | size_t CalculateNumChildren() override { |
| 32 | return m_container_sp ? m_container_sp->GetNumChildren() : 0; |
| 33 | } |
| 34 | |
| 35 | ValueObjectSP GetChildAtIndex(size_t idx) override { |
| 36 | return m_container_sp ? m_container_sp->GetChildAtIndex(idx, true) |
| 37 | : nullptr; |
| 38 | } |
| 39 | |
| 40 | private: |
Cameron Desrochers | 89386da | 2019-10-09 18:27:33 +0000 | [diff] [blame] | 41 | // The lifetime of a ValueObject and all its derivative ValueObjects |
| 42 | // (children, clones, etc.) is managed by a ClusterManager. These |
| 43 | // objects are only destroyed when every shared pointer to any of them |
| 44 | // is destroyed, so we must not store a shared pointer to any ValueObject |
| 45 | // derived from our backend ValueObject (since we're in the same cluster). |
| 46 | ValueObject* m_container_sp = nullptr; |
Pavel Labath | e0d5184 | 2017-11-01 15:52:08 +0000 | [diff] [blame] | 47 | }; |
| 48 | } // namespace |
| 49 | |
| 50 | bool QueueFrontEnd::Update() { |
Cameron Desrochers | 89386da | 2019-10-09 18:27:33 +0000 | [diff] [blame] | 51 | m_container_sp = nullptr; |
Pavel Labath | e0d5184 | 2017-11-01 15:52:08 +0000 | [diff] [blame] | 52 | ValueObjectSP c_sp = m_backend.GetChildMemberWithName(ConstString("c"), true); |
| 53 | if (!c_sp) |
| 54 | return false; |
Cameron Desrochers | 89386da | 2019-10-09 18:27:33 +0000 | [diff] [blame] | 55 | m_container_sp = c_sp->GetSyntheticValue().get(); |
Pavel Labath | e0d5184 | 2017-11-01 15:52:08 +0000 | [diff] [blame] | 56 | return false; |
| 57 | } |
| 58 | |
| 59 | SyntheticChildrenFrontEnd * |
| 60 | formatters::LibcxxQueueFrontEndCreator(CXXSyntheticChildren *, |
| 61 | lldb::ValueObjectSP valobj_sp) { |
| 62 | if (valobj_sp) |
| 63 | return new QueueFrontEnd(*valobj_sp); |
| 64 | return nullptr; |
| 65 | } |