LLDB mainline
LibCxxQueue.cpp
Go to the documentation of this file.
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"
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("Type has no child named '%s'",
27 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("c");
54 if (!c_sp)
56 m_container_sp = c_sp->GetSyntheticValue().get();
58}
59
60SyntheticChildrenFrontEnd *
62 lldb::ValueObjectSP valobj_sp) {
63 if (valobj_sp)
64 return new QueueFrontEnd(*valobj_sp);
65 return nullptr;
66}
static std::optional< size_t > CalculateNumChildren(CompilerType container_elem_type, uint64_t num_elements, CompilerType element_type)
Calculates the number of elements stored in a container (with element type 'container_elem_type') as ...
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
lldb::ValueObjectSP GetSyntheticValue()
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
SyntheticChildrenFrontEnd * LibcxxQueueFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
A class that represents a running process on the host machine.
ChildCacheState
Specifies if children need to be re-computed after a call to SyntheticChildrenFrontEnd::Update.
@ eRefetch
Children need to be recomputed dynamically.
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP