LLDB mainline
GenericQueue.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 "Generic.h"
12#include "llvm/Support/ErrorExtras.h"
13
14using namespace lldb;
15using namespace lldb_private;
16
17namespace {
18
19class ContainerAdaptorFrontEnd : public SyntheticChildrenFrontEnd {
20public:
21 ContainerAdaptorFrontEnd(ValueObject &valobj)
22 : SyntheticChildrenFrontEnd(valobj) {
23 Update();
24 }
25
26 llvm::Expected<size_t>
27 GetIndexOfChildWithName(llvm::StringRef name) override {
28 if (m_container_sp)
29 return m_container_sp->GetIndexOfChildWithName(name);
30 return llvm::createStringErrorV("type has no child named '{0}'", name);
31 }
32
33 lldb::ChildCacheState Update() override;
34
35 llvm::Expected<uint32_t> CalculateNumChildren() override {
36 return m_container_sp ? m_container_sp->GetNumChildren() : 0;
37 }
38
39 ValueObjectSP GetChildAtIndex(uint32_t idx) override {
40 return m_container_sp ? m_container_sp->GetChildAtIndex(idx) : nullptr;
41 }
42
43private:
44 // The lifetime of a ValueObject and all its derivative ValueObjects
45 // (children, clones, etc.) is managed by a ClusterManager. These
46 // objects are only destroyed when every shared pointer to any of them
47 // is destroyed, so we must not store a shared pointer to any ValueObject
48 // derived from our backend ValueObject (since we're in the same cluster).
49 ValueObject *m_container_sp = nullptr;
50};
51} // namespace
52
53lldb::ChildCacheState ContainerAdaptorFrontEnd::Update() {
54 m_container_sp = nullptr;
55 ValueObjectSP c_sp = m_backend.GetChildMemberWithName("c");
56 if (!c_sp)
58 m_container_sp = c_sp->GetSyntheticValue().get();
60}
61
63 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
64 if (valobj_sp)
65 return new ContainerAdaptorFrontEnd(*valobj_sp);
66 return nullptr;
67}
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 ...
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
SyntheticChildrenFrontEnd * GenericContainerAdaptorFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp)
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