1*0b57cec5SDimitry Andric //===-- DataVisualization.cpp ---------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric
9*0b57cec5SDimitry Andric #include "lldb/DataFormatters/DataVisualization.h"
10*0b57cec5SDimitry Andric
11*0b57cec5SDimitry Andric
12*0b57cec5SDimitry Andric using namespace lldb;
13*0b57cec5SDimitry Andric using namespace lldb_private;
14*0b57cec5SDimitry Andric
GetFormatManager()15*0b57cec5SDimitry Andric static FormatManager &GetFormatManager() {
16*0b57cec5SDimitry Andric static FormatManager g_format_manager;
17*0b57cec5SDimitry Andric return g_format_manager;
18*0b57cec5SDimitry Andric }
19*0b57cec5SDimitry Andric
ForceUpdate()20*0b57cec5SDimitry Andric void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); }
21*0b57cec5SDimitry Andric
GetCurrentRevision()22*0b57cec5SDimitry Andric uint32_t DataVisualization::GetCurrentRevision() {
23*0b57cec5SDimitry Andric return GetFormatManager().GetCurrentRevision();
24*0b57cec5SDimitry Andric }
25*0b57cec5SDimitry Andric
ShouldPrintAsOneLiner(ValueObject & valobj)26*0b57cec5SDimitry Andric bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) {
27*0b57cec5SDimitry Andric return GetFormatManager().ShouldPrintAsOneLiner(valobj);
28*0b57cec5SDimitry Andric }
29*0b57cec5SDimitry Andric
30*0b57cec5SDimitry Andric lldb::TypeFormatImplSP
GetFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)31*0b57cec5SDimitry Andric DataVisualization::GetFormat(ValueObject &valobj,
32*0b57cec5SDimitry Andric lldb::DynamicValueType use_dynamic) {
33*0b57cec5SDimitry Andric return GetFormatManager().GetFormat(valobj, use_dynamic);
34*0b57cec5SDimitry Andric }
35*0b57cec5SDimitry Andric
36*0b57cec5SDimitry Andric lldb::TypeFormatImplSP
GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)37*0b57cec5SDimitry Andric DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
38*0b57cec5SDimitry Andric return GetFormatManager().GetFormatForType(type_sp);
39*0b57cec5SDimitry Andric }
40*0b57cec5SDimitry Andric
41*0b57cec5SDimitry Andric lldb::TypeSummaryImplSP
GetSummaryFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)42*0b57cec5SDimitry Andric DataVisualization::GetSummaryFormat(ValueObject &valobj,
43*0b57cec5SDimitry Andric lldb::DynamicValueType use_dynamic) {
44*0b57cec5SDimitry Andric return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
45*0b57cec5SDimitry Andric }
46*0b57cec5SDimitry Andric
47*0b57cec5SDimitry Andric lldb::TypeSummaryImplSP
GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)48*0b57cec5SDimitry Andric DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
49*0b57cec5SDimitry Andric return GetFormatManager().GetSummaryForType(type_sp);
50*0b57cec5SDimitry Andric }
51*0b57cec5SDimitry Andric
52*0b57cec5SDimitry Andric lldb::SyntheticChildrenSP
GetSyntheticChildren(ValueObject & valobj,lldb::DynamicValueType use_dynamic)53*0b57cec5SDimitry Andric DataVisualization::GetSyntheticChildren(ValueObject &valobj,
54*0b57cec5SDimitry Andric lldb::DynamicValueType use_dynamic) {
55*0b57cec5SDimitry Andric return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
56*0b57cec5SDimitry Andric }
57*0b57cec5SDimitry Andric
58*0b57cec5SDimitry Andric lldb::TypeFilterImplSP
GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)59*0b57cec5SDimitry Andric DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
60*0b57cec5SDimitry Andric return GetFormatManager().GetFilterForType(type_sp);
61*0b57cec5SDimitry Andric }
62*0b57cec5SDimitry Andric
63*0b57cec5SDimitry Andric lldb::ScriptedSyntheticChildrenSP
GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)64*0b57cec5SDimitry Andric DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
65*0b57cec5SDimitry Andric return GetFormatManager().GetSyntheticForType(type_sp);
66*0b57cec5SDimitry Andric }
67*0b57cec5SDimitry Andric
AnyMatches(const FormattersMatchCandidate & candidate_type,TypeCategoryImpl::FormatCategoryItems items,bool only_enabled,const char ** matching_category,TypeCategoryImpl::FormatCategoryItems * matching_type)68*0b57cec5SDimitry Andric bool DataVisualization::AnyMatches(
69*0b57cec5SDimitry Andric const FormattersMatchCandidate &candidate_type,
70*0b57cec5SDimitry Andric TypeCategoryImpl::FormatCategoryItems items, bool only_enabled,
71*0b57cec5SDimitry Andric const char **matching_category,
72*0b57cec5SDimitry Andric TypeCategoryImpl::FormatCategoryItems *matching_type) {
73*0b57cec5SDimitry Andric return GetFormatManager().AnyMatches(candidate_type, items, only_enabled,
74*0b57cec5SDimitry Andric matching_category, matching_type);
75*0b57cec5SDimitry Andric }
76*0b57cec5SDimitry Andric
GetCategory(ConstString category,lldb::TypeCategoryImplSP & entry,bool allow_create)77*0b57cec5SDimitry Andric bool DataVisualization::Categories::GetCategory(ConstString category,
78*0b57cec5SDimitry Andric lldb::TypeCategoryImplSP &entry,
79*0b57cec5SDimitry Andric bool allow_create) {
80*0b57cec5SDimitry Andric entry = GetFormatManager().GetCategory(category, allow_create);
81*0b57cec5SDimitry Andric return (entry.get() != nullptr);
82*0b57cec5SDimitry Andric }
83*0b57cec5SDimitry Andric
GetCategory(lldb::LanguageType language,lldb::TypeCategoryImplSP & entry)84*0b57cec5SDimitry Andric bool DataVisualization::Categories::GetCategory(
85*0b57cec5SDimitry Andric lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) {
86*0b57cec5SDimitry Andric if (LanguageCategory *lang_category =
87*0b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(language))
88*0b57cec5SDimitry Andric entry = lang_category->GetCategory();
89*0b57cec5SDimitry Andric return (entry.get() != nullptr);
90*0b57cec5SDimitry Andric }
91*0b57cec5SDimitry Andric
Add(ConstString category)92*0b57cec5SDimitry Andric void DataVisualization::Categories::Add(ConstString category) {
93*0b57cec5SDimitry Andric GetFormatManager().GetCategory(category);
94*0b57cec5SDimitry Andric }
95*0b57cec5SDimitry Andric
Delete(ConstString category)96*0b57cec5SDimitry Andric bool DataVisualization::Categories::Delete(ConstString category) {
97*0b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
98*0b57cec5SDimitry Andric return GetFormatManager().DeleteCategory(category);
99*0b57cec5SDimitry Andric }
100*0b57cec5SDimitry Andric
Clear()101*0b57cec5SDimitry Andric void DataVisualization::Categories::Clear() {
102*0b57cec5SDimitry Andric GetFormatManager().ClearCategories();
103*0b57cec5SDimitry Andric }
104*0b57cec5SDimitry Andric
Clear(ConstString category)105*0b57cec5SDimitry Andric void DataVisualization::Categories::Clear(ConstString category) {
106*0b57cec5SDimitry Andric GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary);
107*0b57cec5SDimitry Andric }
108*0b57cec5SDimitry Andric
Enable(ConstString category,TypeCategoryMap::Position pos)109*0b57cec5SDimitry Andric void DataVisualization::Categories::Enable(ConstString category,
110*0b57cec5SDimitry Andric TypeCategoryMap::Position pos) {
111*0b57cec5SDimitry Andric if (GetFormatManager().GetCategory(category)->IsEnabled())
112*0b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
113*0b57cec5SDimitry Andric GetFormatManager().EnableCategory(category, pos, {});
114*0b57cec5SDimitry Andric }
115*0b57cec5SDimitry Andric
Enable(lldb::LanguageType lang_type)116*0b57cec5SDimitry Andric void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) {
117*0b57cec5SDimitry Andric if (LanguageCategory *lang_category =
118*0b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(lang_type))
119*0b57cec5SDimitry Andric lang_category->Enable();
120*0b57cec5SDimitry Andric }
121*0b57cec5SDimitry Andric
Disable(ConstString category)122*0b57cec5SDimitry Andric void DataVisualization::Categories::Disable(ConstString category) {
123*0b57cec5SDimitry Andric if (GetFormatManager().GetCategory(category)->IsEnabled())
124*0b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
125*0b57cec5SDimitry Andric }
126*0b57cec5SDimitry Andric
Disable(lldb::LanguageType lang_type)127*0b57cec5SDimitry Andric void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) {
128*0b57cec5SDimitry Andric if (LanguageCategory *lang_category =
129*0b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(lang_type))
130*0b57cec5SDimitry Andric lang_category->Disable();
131*0b57cec5SDimitry Andric }
132*0b57cec5SDimitry Andric
Enable(const lldb::TypeCategoryImplSP & category,TypeCategoryMap::Position pos)133*0b57cec5SDimitry Andric void DataVisualization::Categories::Enable(
134*0b57cec5SDimitry Andric const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) {
135*0b57cec5SDimitry Andric if (category.get()) {
136*0b57cec5SDimitry Andric if (category->IsEnabled())
137*0b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
138*0b57cec5SDimitry Andric GetFormatManager().EnableCategory(category, pos);
139*0b57cec5SDimitry Andric }
140*0b57cec5SDimitry Andric }
141*0b57cec5SDimitry Andric
Disable(const lldb::TypeCategoryImplSP & category)142*0b57cec5SDimitry Andric void DataVisualization::Categories::Disable(
143*0b57cec5SDimitry Andric const lldb::TypeCategoryImplSP &category) {
144*0b57cec5SDimitry Andric if (category.get() && category->IsEnabled())
145*0b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
146*0b57cec5SDimitry Andric }
147*0b57cec5SDimitry Andric
EnableStar()148*0b57cec5SDimitry Andric void DataVisualization::Categories::EnableStar() {
149*0b57cec5SDimitry Andric GetFormatManager().EnableAllCategories();
150*0b57cec5SDimitry Andric }
151*0b57cec5SDimitry Andric
DisableStar()152*0b57cec5SDimitry Andric void DataVisualization::Categories::DisableStar() {
153*0b57cec5SDimitry Andric GetFormatManager().DisableAllCategories();
154*0b57cec5SDimitry Andric }
155*0b57cec5SDimitry Andric
ForEach(TypeCategoryMap::ForEachCallback callback)156*0b57cec5SDimitry Andric void DataVisualization::Categories::ForEach(
157*0b57cec5SDimitry Andric TypeCategoryMap::ForEachCallback callback) {
158*0b57cec5SDimitry Andric GetFormatManager().ForEachCategory(callback);
159*0b57cec5SDimitry Andric }
160*0b57cec5SDimitry Andric
GetCount()161*0b57cec5SDimitry Andric uint32_t DataVisualization::Categories::GetCount() {
162*0b57cec5SDimitry Andric return GetFormatManager().GetCategoriesCount();
163*0b57cec5SDimitry Andric }
164*0b57cec5SDimitry Andric
165*0b57cec5SDimitry Andric lldb::TypeCategoryImplSP
GetCategoryAtIndex(size_t index)166*0b57cec5SDimitry Andric DataVisualization::Categories::GetCategoryAtIndex(size_t index) {
167*0b57cec5SDimitry Andric return GetFormatManager().GetCategoryAtIndex(index);
168*0b57cec5SDimitry Andric }
169*0b57cec5SDimitry Andric
GetSummaryFormat(ConstString type,lldb::TypeSummaryImplSP & entry)170*0b57cec5SDimitry Andric bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
171*0b57cec5SDimitry Andric ConstString type, lldb::TypeSummaryImplSP &entry) {
172*0b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().GetExact(type, entry);
173*0b57cec5SDimitry Andric }
174*0b57cec5SDimitry Andric
Add(ConstString type,const lldb::TypeSummaryImplSP & entry)175*0b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::Add(
176*0b57cec5SDimitry Andric ConstString type, const lldb::TypeSummaryImplSP &entry) {
177*0b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().Add(type, entry);
178*0b57cec5SDimitry Andric }
179*0b57cec5SDimitry Andric
Delete(ConstString type)180*0b57cec5SDimitry Andric bool DataVisualization::NamedSummaryFormats::Delete(ConstString type) {
181*0b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().Delete(type);
182*0b57cec5SDimitry Andric }
183*0b57cec5SDimitry Andric
Clear()184*0b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::Clear() {
185*0b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().Clear();
186*0b57cec5SDimitry Andric }
187*0b57cec5SDimitry Andric
ForEach(std::function<bool (const TypeMatcher &,const lldb::TypeSummaryImplSP &)> callback)188*0b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::ForEach(
189*0b57cec5SDimitry Andric std::function<bool(const TypeMatcher &, const lldb::TypeSummaryImplSP &)>
190*0b57cec5SDimitry Andric callback) {
191*0b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().ForEach(callback);
192*0b57cec5SDimitry Andric }
193*0b57cec5SDimitry Andric
GetCount()194*0b57cec5SDimitry Andric uint32_t DataVisualization::NamedSummaryFormats::GetCount() {
195*0b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().GetCount();
196*0b57cec5SDimitry Andric }
197*0b57cec5SDimitry Andric