blob: b6d664df16ef968595015cbf59ffef0dfe7bbb4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
//===-- LibStdcppUniquePointer.cpp ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LibStdcpp.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/DataFormatters/TypeSynthetic.h"
#include "lldb/Utility/ConstString.h"
#include <memory>
#include <vector>
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
namespace {
class LibStdcppUniquePtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
public:
explicit LibStdcppUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
size_t CalculateNumChildren() override;
lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
bool Update() override;
bool MightHaveChildren() override;
size_t GetIndexOfChildWithName(const ConstString &name) override;
bool GetSummary(Stream &stream, const TypeSummaryOptions &options);
private:
ValueObjectSP m_ptr_obj;
ValueObjectSP m_obj_obj;
ValueObjectSP m_del_obj;
};
} // end of anonymous namespace
LibStdcppUniquePtrSyntheticFrontEnd::LibStdcppUniquePtrSyntheticFrontEnd(
lldb::ValueObjectSP valobj_sp)
: SyntheticChildrenFrontEnd(*valobj_sp) {
Update();
}
bool LibStdcppUniquePtrSyntheticFrontEnd::Update() {
ValueObjectSP valobj_backend_sp = m_backend.GetSP();
if (!valobj_backend_sp)
return false;
ValueObjectSP valobj_sp = valobj_backend_sp->GetNonSyntheticValue();
if (!valobj_sp)
return false;
ValueObjectSP tuple_sp =
valobj_sp->GetChildMemberWithName(ConstString("_M_t"), true);
if (!tuple_sp)
return false;
std::unique_ptr<SyntheticChildrenFrontEnd> tuple_frontend(
LibStdcppTupleSyntheticFrontEndCreator(nullptr, tuple_sp));
ValueObjectSP ptr_obj = tuple_frontend->GetChildAtIndex(0);
if (ptr_obj)
m_ptr_obj = ptr_obj->Clone(ConstString("pointer"));
ValueObjectSP del_obj = tuple_frontend->GetChildAtIndex(1);
if (del_obj)
m_del_obj = del_obj->Clone(ConstString("deleter"));
if (m_ptr_obj) {
Status error;
ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
if (error.Success()) {
m_obj_obj = obj_obj->Clone(ConstString("object"));
}
}
return false;
}
bool LibStdcppUniquePtrSyntheticFrontEnd::MightHaveChildren() { return true; }
lldb::ValueObjectSP
LibStdcppUniquePtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
if (idx == 0)
return m_ptr_obj;
if (idx == 1)
return m_del_obj;
if (idx == 2)
return m_obj_obj;
return lldb::ValueObjectSP();
}
size_t LibStdcppUniquePtrSyntheticFrontEnd::CalculateNumChildren() {
if (m_del_obj)
return 2;
return 1;
}
size_t LibStdcppUniquePtrSyntheticFrontEnd::GetIndexOfChildWithName(
const ConstString &name) {
if (name == ConstString("ptr") || name == ConstString("pointer"))
return 0;
if (name == ConstString("del") || name == ConstString("deleter"))
return 1;
if (name == ConstString("obj") || name == ConstString("object") ||
name == ConstString("$$dereference$$"))
return 2;
return UINT32_MAX;
}
bool LibStdcppUniquePtrSyntheticFrontEnd::GetSummary(
Stream &stream, const TypeSummaryOptions &options) {
if (!m_ptr_obj)
return false;
bool success;
uint64_t ptr_value = m_ptr_obj->GetValueAsUnsigned(0, &success);
if (!success)
return false;
if (ptr_value == 0)
stream.Printf("nullptr");
else
stream.Printf("0x%" PRIx64, ptr_value);
return true;
}
SyntheticChildrenFrontEnd *
lldb_private::formatters::LibStdcppUniquePtrSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
return (valobj_sp ? new LibStdcppUniquePtrSyntheticFrontEnd(valobj_sp)
: nullptr);
}
bool lldb_private::formatters::LibStdcppUniquePointerSummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
LibStdcppUniquePtrSyntheticFrontEnd formatter(valobj.GetSP());
return formatter.GetSummary(stream, options);
}
|