LLDB mainline
LibCxxTuple.cpp
Go to the documentation of this file.
1//===-- LibCxxTuple.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 TupleFrontEnd: public SyntheticChildrenFrontEnd {
18public:
19 TupleFrontEnd(ValueObject &valobj) : SyntheticChildrenFrontEnd(valobj) {
20 Update();
21 }
22
23 size_t GetIndexOfChildWithName(ConstString name) override {
25 }
26
27 bool MightHaveChildren() override { return true; }
29 llvm::Expected<uint32_t> CalculateNumChildren() override {
30 return m_elements.size();
31 }
32 ValueObjectSP GetChildAtIndex(uint32_t idx) override;
33
34private:
35 // The lifetime of a ValueObject and all its derivative ValueObjects
36 // (children, clones, etc.) is managed by a ClusterManager. These
37 // objects are only destroyed when every shared pointer to any of them
38 // is destroyed, so we must not store a shared pointer to any ValueObject
39 // derived from our backend ValueObject (since we're in the same cluster).
40 std::vector<ValueObject*> m_elements;
41 ValueObject* m_base = nullptr;
42};
43}
44
45lldb::ChildCacheState TupleFrontEnd::Update() {
46 m_elements.clear();
47 m_base = nullptr;
48
49 ValueObjectSP base_sp;
50 base_sp = m_backend.GetChildMemberWithName("__base_");
51 if (!base_sp) {
52 // Pre r304382 name of the base element.
53 base_sp = m_backend.GetChildMemberWithName("base_");
54 }
55 if (!base_sp)
57 m_base = base_sp.get();
58 m_elements.assign(base_sp->GetCompilerType().GetNumDirectBaseClasses(),
59 nullptr);
61}
62
63ValueObjectSP TupleFrontEnd::GetChildAtIndex(uint32_t idx) {
64 if (idx >= m_elements.size())
65 return ValueObjectSP();
66 if (!m_base)
67 return ValueObjectSP();
68 if (m_elements[idx])
69 return m_elements[idx]->GetSP();
70
71 CompilerType holder_type =
72 m_base->GetCompilerType().GetDirectBaseClassAtIndex(idx, nullptr);
73 if (!holder_type)
74 return ValueObjectSP();
75 ValueObjectSP holder_sp = m_base->GetChildAtIndex(idx);
76 if (!holder_sp)
77 return ValueObjectSP();
78
79 ValueObjectSP elem_sp = holder_sp->GetChildAtIndex(0);
80 if (elem_sp)
81 m_elements[idx] =
82 elem_sp->Clone(ConstString(llvm::formatv("[{0}]", idx).str())).get();
83
84 if (m_elements[idx])
85 return m_elements[idx]->GetSP();
86 return ValueObjectSP();
87}
88
91 lldb::ValueObjectSP valobj_sp) {
92 if (valobj_sp)
93 return new TupleFrontEnd(*valobj_sp);
94 return nullptr;
95}
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
CompilerType GetDirectBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
A uniqued constant string class.
Definition: ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
virtual lldb::ValueObjectSP GetChildAtIndex(uint32_t idx)=0
virtual lldb::ChildCacheState Update()=0
This function is assumed to always succeed and if it fails, the front-end should know to deal with it...
virtual size_t GetIndexOfChildWithName(ConstString name)=0
virtual llvm::Expected< uint32_t > CalculateNumChildren()=0
virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name, bool can_create=true)
SyntheticChildrenFrontEnd * LibcxxTupleFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
Definition: LibCxxTuple.cpp:90
size_t ExtractIndexFromString(const char *item_name)
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
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
Definition: lldb-forward.h:484