1 //===-- LibStdcppTuple.cpp --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
11 #include "lldb/Core/ValueObject.h"
12 #include "lldb/DataFormatters/FormattersHelpers.h"
13 #include "lldb/DataFormatters/TypeSynthetic.h"
14 #include "lldb/Utility/ConstString.h"
20 using namespace lldb_private;
21 using namespace lldb_private::formatters;
25 class LibStdcppTupleSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
27 explicit LibStdcppTupleSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
29 size_t CalculateNumChildren() override;
31 lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
33 bool Update() override;
35 bool MightHaveChildren() override;
37 size_t GetIndexOfChildWithName(ConstString name) override;
40 std::vector<ValueObjectSP> m_members;
43 } // end of anonymous namespace
45 LibStdcppTupleSyntheticFrontEnd::LibStdcppTupleSyntheticFrontEnd(
46 lldb::ValueObjectSP valobj_sp)
47 : SyntheticChildrenFrontEnd(*valobj_sp) {
51 bool LibStdcppTupleSyntheticFrontEnd::Update() {
54 ValueObjectSP valobj_backend_sp = m_backend.GetSP();
55 if (!valobj_backend_sp)
58 ValueObjectSP next_child_sp = valobj_backend_sp->GetNonSyntheticValue();
59 while (next_child_sp != nullptr) {
60 ValueObjectSP current_child = next_child_sp;
61 next_child_sp = nullptr;
63 size_t child_count = current_child->GetNumChildren();
64 for (size_t i = 0; i < child_count; ++i) {
65 ValueObjectSP child_sp = current_child->GetChildAtIndex(i, true);
66 llvm::StringRef name_str = child_sp->GetName().GetStringRef();
67 if (name_str.startswith("std::_Tuple_impl<")) {
68 next_child_sp = child_sp;
69 } else if (name_str.startswith("std::_Head_base<")) {
70 ValueObjectSP value_sp =
71 child_sp->GetChildMemberWithName(ConstString("_M_head_impl"), true);
74 name.Printf("[%zd]", m_members.size());
75 m_members.push_back(value_sp->Clone(ConstString(name.GetString())));
84 bool LibStdcppTupleSyntheticFrontEnd::MightHaveChildren() { return true; }
87 LibStdcppTupleSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
88 if (idx < m_members.size())
89 return m_members[idx];
90 return lldb::ValueObjectSP();
93 size_t LibStdcppTupleSyntheticFrontEnd::CalculateNumChildren() {
94 return m_members.size();
97 size_t LibStdcppTupleSyntheticFrontEnd::GetIndexOfChildWithName(
99 return ExtractIndexFromString(name.GetCString());
102 SyntheticChildrenFrontEnd *
103 lldb_private::formatters::LibStdcppTupleSyntheticFrontEndCreator(
104 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
105 return (valobj_sp ? new LibStdcppTupleSyntheticFrontEnd(valobj_sp) : nullptr);