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;
48 } // end of anonymous namespace
50 LibStdcppUniquePtrSyntheticFrontEnd::LibStdcppUniquePtrSyntheticFrontEnd(
51 lldb::ValueObjectSP valobj_sp)
52 : SyntheticChildrenFrontEnd(*valobj_sp) {
56 bool LibStdcppUniquePtrSyntheticFrontEnd::Update() {
57 ValueObjectSP valobj_backend_sp = m_backend.GetSP();
58 if (!valobj_backend_sp)
61 ValueObjectSP valobj_sp = valobj_backend_sp->GetNonSyntheticValue();
65 ValueObjectSP tuple_sp =
66 valobj_sp->GetChildMemberWithName(ConstString("_M_t"), true);
70 std::unique_ptr<SyntheticChildrenFrontEnd> tuple_frontend(
71 LibStdcppTupleSyntheticFrontEndCreator(nullptr, tuple_sp));
73 ValueObjectSP ptr_obj = tuple_frontend->GetChildAtIndex(0);
75 m_ptr_obj = ptr_obj->Clone(ConstString("pointer"));
77 ValueObjectSP del_obj = tuple_frontend->GetChildAtIndex(1);
79 m_del_obj = del_obj->Clone(ConstString("deleter"));
83 ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
84 if (error.Success()) {
85 m_obj_obj = obj_obj->Clone(ConstString("object"));
92 bool LibStdcppUniquePtrSyntheticFrontEnd::MightHaveChildren() { return true; }
95 LibStdcppUniquePtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
102 return lldb::ValueObjectSP();
105 size_t LibStdcppUniquePtrSyntheticFrontEnd::CalculateNumChildren() {
111 size_t LibStdcppUniquePtrSyntheticFrontEnd::GetIndexOfChildWithName(
112 const ConstString &name) {
113 if (name == ConstString("ptr") || name == ConstString("pointer"))
115 if (name == ConstString("del") || name == ConstString("deleter"))
117 if (name == ConstString("obj") || name == ConstString("object") ||
118 name == ConstString("$$dereference$$"))
123 bool LibStdcppUniquePtrSyntheticFrontEnd::GetSummary(
124 Stream &stream, const TypeSummaryOptions &options) {
129 uint64_t ptr_value = m_ptr_obj->GetValueAsUnsigned(0, &success);
133 stream.Printf("nullptr");
135 stream.Printf("0x%" PRIx64, ptr_value);
139 SyntheticChildrenFrontEnd *
140 lldb_private::formatters::LibStdcppUniquePtrSyntheticFrontEndCreator(
141 CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
142 return (valobj_sp ? new LibStdcppUniquePtrSyntheticFrontEnd(valobj_sp)
146 bool lldb_private::formatters::LibStdcppUniquePointerSummaryProvider(
147 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
148 LibStdcppUniquePtrSyntheticFrontEnd formatter(valobj.GetSP());
149 return formatter.GetSummary(stream, options);