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> GetIndexOfChildWithName(ConstString name) override {
27 if (m_container_sp)
28 return m_container_sp->GetIndexOfChildWithName(name);
29 return llvm::createStringErrorV("type has no child named '{0}'", name);
30 }
31
32 lldb::ChildCacheState Update() override;
33
34 llvm::Expected<uint32_t> CalculateNumChildren() override {
35 return m_container_sp ? m_container_sp->GetNumChildren() : 0;
36 }
37
38 ValueObjectSP GetChildAtIndex(uint32_t idx) override {
39 return m_container_sp ? m_container_sp->GetChildAtIndex(idx) : nullptr;
40 }
41
42private:
43 // The lifetime of a ValueObject and all its derivative ValueObjects
44 // (children, clones, etc.) is managed by a ClusterManager. These
45 // objects are only destroyed when every shared pointer to any of them
46 // is destroyed, so we must not store a shared pointer to any ValueObject
47 // derived from our backend ValueObject (since we're in the same cluster).
48 ValueObject *m_container_sp = nullptr;
49};
50} // namespace
51
52lldb::ChildCacheState ContainerAdaptorFrontEnd::Update() {
53 m_container_sp = nullptr;
54 ValueObjectSP c_sp = m_backend.GetChildMemberWithName("c");
55 if (!c_sp)
57 m_container_sp = c_sp->GetSyntheticValue().get();
59}
60
62 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
63 if (valobj_sp)
64 return new ContainerAdaptorFrontEnd(*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 ...
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