1//===-- LibCxxQueue.cpp ---------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "LibCxx.h"
10#include "lldb/DataFormatters/FormattersHelpers.h"
11
12using namespace lldb;
13using namespace lldb_private;
14
15namespace {
16
17class QueueFrontEnd : public SyntheticChildrenFrontEnd {
18public:
19 QueueFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
20 Update();
21 }
22
23 llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override {
24 if (m_container_sp)
25 return m_container_sp->GetIndexOfChildWithName(name);
26 return llvm::createStringError(Fmt: "Type has no child named '%s'",
27 Vals: name.AsCString());
28 }
29
30 lldb::ChildCacheState Update() override;
31
32 llvm::Expected<uint32_t> CalculateNumChildren() override {
33 return m_container_sp ? m_container_sp->GetNumChildren() : 0;
34 }
35
36 ValueObjectSP GetChildAtIndex(uint32_t idx) override {
37 return m_container_sp ? m_container_sp->GetChildAtIndex(idx)
38 : nullptr;
39 }
40
41private:
42 // The lifetime of a ValueObject and all its derivative ValueObjects
43 // (children, clones, etc.) is managed by a ClusterManager. These
44 // objects are only destroyed when every shared pointer to any of them
45 // is destroyed, so we must not store a shared pointer to any ValueObject
46 // derived from our backend ValueObject (since we're in the same cluster).
47 ValueObject* m_container_sp = nullptr;
48};
49} // namespace
50
51lldb::ChildCacheState QueueFrontEnd::Update() {
52 m_container_sp = nullptr;
53 ValueObjectSP c_sp = m_backend.GetChildMemberWithName(name: "c");
54 if (!c_sp)
55 return lldb::ChildCacheState::eRefetch;
56 m_container_sp = c_sp->GetSyntheticValue().get();
57 return lldb::ChildCacheState::eRefetch;
58}
59
60SyntheticChildrenFrontEnd *
61formatters::LibcxxQueueFrontEndCreator(CXXSyntheticChildren *,
62 lldb::ValueObjectSP valobj_sp) {
63 if (valobj_sp)
64 return new QueueFrontEnd(*valobj_sp);
65 return nullptr;
66}
67

source code of lldb/source/Plugins/Language/CPlusPlus/LibCxxQueue.cpp