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; }
28 bool Update() override;
29 size_t CalculateNumChildren() override { return m_elements.size(); }
30 ValueObjectSP GetChildAtIndex(size_t idx) override;
31
32private:
33 // The lifetime of a ValueObject and all its derivative ValueObjects
34 // (children, clones, etc.) is managed by a ClusterManager. These
35 // objects are only destroyed when every shared pointer to any of them
36 // is destroyed, so we must not store a shared pointer to any ValueObject
37 // derived from our backend ValueObject (since we're in the same cluster).
38 std::vector<ValueObject*> m_elements;
39 ValueObject* m_base = nullptr;
40};
41}
42
43bool TupleFrontEnd::Update() {
44 m_elements.clear();
45 m_base = nullptr;
46
47 ValueObjectSP base_sp;
48 base_sp = m_backend.GetChildMemberWithName(ConstString("__base_"), true);
49 if (!base_sp) {
50 // Pre r304382 name of the base element.
51 base_sp = m_backend.GetChildMemberWithName(ConstString("base_"), true);
52 }
53 if (!base_sp)
54 return false;
55 m_base = base_sp.get();
56 m_elements.assign(base_sp->GetCompilerType().GetNumDirectBaseClasses(),
57 nullptr);
58 return false;
59}
60
61ValueObjectSP TupleFrontEnd::GetChildAtIndex(size_t idx) {
62 if (idx >= m_elements.size())
63 return ValueObjectSP();
64 if (!m_base)
65 return ValueObjectSP();
66 if (m_elements[idx])
67 return m_elements[idx]->GetSP();
68
69 CompilerType holder_type =
70 m_base->GetCompilerType().GetDirectBaseClassAtIndex(idx, nullptr);
71 if (!holder_type)
72 return ValueObjectSP();
73 ValueObjectSP holder_sp = m_base->GetChildAtIndex(idx, true);
74 if (!holder_sp)
75 return ValueObjectSP();
76
77 ValueObjectSP elem_sp = holder_sp->GetChildAtIndex(0, true);
78 if (elem_sp)
79 m_elements[idx] =
80 elem_sp->Clone(ConstString(llvm::formatv("[{0}]", idx).str())).get();
81
82 if (m_elements[idx])
83 return m_elements[idx]->GetSP();
84 return ValueObjectSP();
85}
86
89 lldb::ValueObjectSP valobj_sp) {
90 if (valobj_sp)
91 return new TupleFrontEnd(*valobj_sp);
92 return nullptr;
93}
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:39
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:218
virtual size_t GetIndexOfChildWithName(ConstString name)=0
virtual lldb::ValueObjectSP GetChildAtIndex(size_t idx)=0
virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name, bool can_create)
SyntheticChildrenFrontEnd * LibcxxTupleFrontEndCreator(CXXSyntheticChildren *, lldb::ValueObjectSP)
Definition: LibCxxTuple.cpp:88
size_t ExtractIndexFromString(const char *item_name)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15