1 //===-- LibStdcppUniquePointer.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "LibStdcpp.h"
12 #include "lldb/Core/ValueObject.h"
13 #include "lldb/DataFormatters/FormattersHelpers.h"
14 #include "lldb/DataFormatters/TypeSynthetic.h"
15 #include "lldb/Utility/ConstString.h"
21 using namespace lldb_private;
22 using namespace lldb_private::formatters;
26 class LibStdcppUniquePtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
28 explicit LibStdcppUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
30 size_t CalculateNumChildren() override;
32 lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
34 bool Update() override;
36 bool MightHaveChildren() override;
38 size_t GetIndexOfChildWithName(const ConstString &name) override;
40 bool GetSummary(Stream &stream, const TypeSummaryOptions &options);
43 ValueObjectSP m_ptr_obj;
44 ValueObjectSP m_obj_obj;
45 ValueObjectSP m_del_obj;
47 ValueObjectSP GetTuple();
50 } // end of anonymous namespace
52 LibStdcppUniquePtrSyntheticFrontEnd::LibStdcppUniquePtrSyntheticFrontEnd(
53 lldb::ValueObjectSP valobj_sp)
54 : SyntheticChildrenFrontEnd(*valobj_sp) {
58 ValueObjectSP LibStdcppUniquePtrSyntheticFrontEnd::GetTuple() {
59 ValueObjectSP valobj_backend_sp = m_backend.GetSP();
61 if (!valobj_backend_sp)
64 ValueObjectSP valobj_sp = valobj_backend_sp->GetNonSyntheticValue();
68 ValueObjectSP obj_child_sp =
69 valobj_sp->GetChildMemberWithName(ConstString("_M_t"), true);
73 ValueObjectSP obj_subchild_sp =
74 obj_child_sp->GetChildMemberWithName(ConstString("_M_t"), true);
76 // if there is a _M_t subchild, the tuple is found in the obj_subchild_sp
77 // (for libstdc++ 6.0.23).
78 if (obj_subchild_sp) {
79 return obj_subchild_sp;
85 bool LibStdcppUniquePtrSyntheticFrontEnd::Update() {
86 ValueObjectSP tuple_sp = GetTuple();
91 std::unique_ptr<SyntheticChildrenFrontEnd> tuple_frontend(
92 LibStdcppTupleSyntheticFrontEndCreator(nullptr, tuple_sp));
94 ValueObjectSP ptr_obj = tuple_frontend->GetChildAtIndex(0);
96 m_ptr_obj = ptr_obj->Clone(ConstString("pointer"));
98 ValueObjectSP del_obj = tuple_frontend->GetChildAtIndex(1);
100 m_del_obj = del_obj->Clone(ConstString("deleter"));
104 ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
105 if (error.Success()) {
106 m_obj_obj = obj_obj->Clone(ConstString("object"));
113 bool LibStdcppUniquePtrSyntheticFrontEnd::MightHaveChildren() { return true; }
116 LibStdcppUniquePtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
123 return lldb::ValueObjectSP();
126 size_t LibStdcppUniquePtrSyntheticFrontEnd::CalculateNumChildren() {
132 size_t LibStdcppUniquePtrSyntheticFrontEnd::GetIndexOfChildWithName(
133 const ConstString &name) {
134 if (name == ConstString("ptr") || name == ConstString("pointer"))
136 if (name == ConstString("del") || name == ConstString("deleter"))
138 if (name == ConstString("obj") || name == ConstString("object") ||
139 name == ConstString("$$dereference$$"))
144 bool LibStdcppUniquePtrSyntheticFrontEnd::GetSummary(
145 Stream &stream, const TypeSummaryOptions &options) {
150 uint64_t ptr_value = m_ptr_obj->GetValueAsUnsigned(0, &success);
154 stream.Printf("nullptr");
156 stream.Printf("0x%" PRIx64, ptr_value);
160 SyntheticChildrenFrontEnd *
161 lldb_private::formatters::LibStdcppUniquePtrSyntheticFrontEndCreator(
162 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
163 return (valobj_sp ? new LibStdcppUniquePtrSyntheticFrontEnd(valobj_sp)
167 bool lldb_private::formatters::LibStdcppUniquePointerSummaryProvider(
168 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
169 LibStdcppUniquePtrSyntheticFrontEnd formatter(valobj.GetSP());
170 return formatter.GetSummary(stream, options);