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