1 //===-- DataVisualization.cpp ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/lldb-python.h"
11 
12 #include "lldb/DataFormatters/DataVisualization.h"
13 
14 // C Includes
15 // C++ Includes
16 // Other libraries and framework includes
17 // Project includes
18 
19 #include "lldb/Core/Debugger.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
24 static FormatManager&
25 GetFormatManager()
26 {
27     static FormatManager g_format_manager;
28     return g_format_manager;
29 }
30 
31 void
32 DataVisualization::ForceUpdate ()
33 {
34     GetFormatManager().Changed();
35 }
36 
37 uint32_t
38 DataVisualization::GetCurrentRevision ()
39 {
40     return GetFormatManager().GetCurrentRevision();
41 }
42 
43 bool
44 DataVisualization::ShouldPrintAsOneLiner (ValueObject& valobj)
45 {
46     return GetFormatManager().ShouldPrintAsOneLiner(valobj);
47 }
48 
49 lldb::TypeFormatImplSP
50 DataVisualization::ValueFormats::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic)
51 {
52     lldb::TypeFormatImplSP entry;
53     GetFormatManager().GetValueNavigator().Get(valobj, entry, use_dynamic);
54     return entry;
55 }
56 
57 lldb::TypeFormatImplSP
58 DataVisualization::ValueFormats::GetFormat (const ConstString &type)
59 {
60     lldb::TypeFormatImplSP entry;
61     GetFormatManager().GetValueNavigator().Get(type, entry);
62     return entry;
63 }
64 
65 void
66 DataVisualization::ValueFormats::Add (const ConstString &type, const lldb::TypeFormatImplSP &entry)
67 {
68     GetFormatManager().GetValueNavigator().Add(FormatManager::GetValidTypeName(type),entry);
69 }
70 
71 bool
72 DataVisualization::ValueFormats::Delete (const ConstString &type)
73 {
74     return GetFormatManager().GetValueNavigator().Delete(type);
75 }
76 
77 void
78 DataVisualization::ValueFormats::Clear ()
79 {
80     GetFormatManager().GetValueNavigator().Clear();
81 }
82 
83 void
84 DataVisualization::ValueFormats::LoopThrough (TypeFormatImpl::ValueCallback callback, void* callback_baton)
85 {
86     GetFormatManager().GetValueNavigator().LoopThrough(callback, callback_baton);
87 }
88 
89 size_t
90 DataVisualization::ValueFormats::GetCount ()
91 {
92     return GetFormatManager().GetValueNavigator().GetCount();
93 }
94 
95 lldb::TypeNameSpecifierImplSP
96 DataVisualization::ValueFormats::GetTypeNameSpecifierForFormatAtIndex (size_t index)
97 {
98     return GetFormatManager().GetValueNavigator().GetTypeNameSpecifierAtIndex(index);
99 }
100 
101 lldb::TypeFormatImplSP
102 DataVisualization::ValueFormats::GetFormatAtIndex (size_t index)
103 {
104     return GetFormatManager().GetValueNavigator().GetAtIndex(index);
105 }
106 
107 lldb::TypeSummaryImplSP
108 DataVisualization::GetSummaryFormat (ValueObject& valobj,
109                                      lldb::DynamicValueType use_dynamic)
110 {
111     return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
112 }
113 
114 lldb::TypeSummaryImplSP
115 DataVisualization::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp)
116 {
117     return GetFormatManager().GetSummaryForType(type_sp);
118 }
119 
120 #ifndef LLDB_DISABLE_PYTHON
121 lldb::SyntheticChildrenSP
122 DataVisualization::GetSyntheticChildren (ValueObject& valobj,
123                                          lldb::DynamicValueType use_dynamic)
124 {
125     return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
126 }
127 #endif
128 
129 #ifndef LLDB_DISABLE_PYTHON
130 lldb::SyntheticChildrenSP
131 DataVisualization::GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp)
132 {
133     return GetFormatManager().GetSyntheticChildrenForType(type_sp);
134 }
135 #endif
136 
137 lldb::TypeFilterImplSP
138 DataVisualization::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp)
139 {
140     return GetFormatManager().GetFilterForType(type_sp);
141 }
142 
143 #ifndef LLDB_DISABLE_PYTHON
144 lldb::ScriptedSyntheticChildrenSP
145 DataVisualization::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp)
146 {
147     return GetFormatManager().GetSyntheticForType(type_sp);
148 }
149 #endif
150 
151 bool
152 DataVisualization::AnyMatches (ConstString type_name,
153                                TypeCategoryImpl::FormatCategoryItems items,
154                                bool only_enabled,
155                                const char** matching_category,
156                                TypeCategoryImpl::FormatCategoryItems* matching_type)
157 {
158     return GetFormatManager().AnyMatches(type_name,
159                                          items,
160                                          only_enabled,
161                                          matching_category,
162                                          matching_type);
163 }
164 
165 bool
166 DataVisualization::Categories::GetCategory (const ConstString &category, lldb::TypeCategoryImplSP &entry,
167                                             bool allow_create)
168 {
169     entry = GetFormatManager().GetCategory(category, allow_create);
170     return (entry.get() != NULL);
171 }
172 
173 void
174 DataVisualization::Categories::Add (const ConstString &category)
175 {
176     GetFormatManager().GetCategory(category);
177 }
178 
179 bool
180 DataVisualization::Categories::Delete (const ConstString &category)
181 {
182     GetFormatManager().DisableCategory(category);
183     return GetFormatManager().DeleteCategory(category);
184 }
185 
186 void
187 DataVisualization::Categories::Clear ()
188 {
189     GetFormatManager().ClearCategories();
190 }
191 
192 void
193 DataVisualization::Categories::Clear (const ConstString &category)
194 {
195     GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
196 }
197 
198 void
199 DataVisualization::Categories::Enable (const ConstString& category,
200                                        TypeCategoryMap::Position pos)
201 {
202     if (GetFormatManager().GetCategory(category)->IsEnabled())
203         GetFormatManager().DisableCategory(category);
204     GetFormatManager().EnableCategory(category, pos);
205 }
206 
207 void
208 DataVisualization::Categories::Disable (const ConstString& category)
209 {
210     if (GetFormatManager().GetCategory(category)->IsEnabled() == true)
211         GetFormatManager().DisableCategory(category);
212 }
213 
214 void
215 DataVisualization::Categories::Enable (const lldb::TypeCategoryImplSP& category,
216                                        TypeCategoryMap::Position pos)
217 {
218     if (category.get())
219     {
220         if (category->IsEnabled())
221             GetFormatManager().DisableCategory(category);
222         GetFormatManager().EnableCategory(category, pos);
223     }
224 }
225 
226 void
227 DataVisualization::Categories::Disable (const lldb::TypeCategoryImplSP& category)
228 {
229     if (category.get() && category->IsEnabled() == true)
230         GetFormatManager().DisableCategory(category);
231 }
232 
233 void
234 DataVisualization::Categories::LoopThrough (FormatManager::CategoryCallback callback, void* callback_baton)
235 {
236     GetFormatManager().LoopThroughCategories(callback, callback_baton);
237 }
238 
239 uint32_t
240 DataVisualization::Categories::GetCount ()
241 {
242     return GetFormatManager().GetCategoriesCount();
243 }
244 
245 lldb::TypeCategoryImplSP
246 DataVisualization::Categories::GetCategoryAtIndex (size_t index)
247 {
248     return GetFormatManager().GetCategoryAtIndex(index);
249 }
250 
251 bool
252 DataVisualization::NamedSummaryFormats::GetSummaryFormat (const ConstString &type, lldb::TypeSummaryImplSP &entry)
253 {
254     return GetFormatManager().GetNamedSummaryNavigator().Get(type,entry);
255 }
256 
257 void
258 DataVisualization::NamedSummaryFormats::Add (const ConstString &type, const lldb::TypeSummaryImplSP &entry)
259 {
260     GetFormatManager().GetNamedSummaryNavigator().Add(FormatManager::GetValidTypeName(type),entry);
261 }
262 
263 bool
264 DataVisualization::NamedSummaryFormats::Delete (const ConstString &type)
265 {
266     return GetFormatManager().GetNamedSummaryNavigator().Delete(type);
267 }
268 
269 void
270 DataVisualization::NamedSummaryFormats::Clear ()
271 {
272     GetFormatManager().GetNamedSummaryNavigator().Clear();
273 }
274 
275 void
276 DataVisualization::NamedSummaryFormats::LoopThrough (TypeSummaryImpl::SummaryCallback callback, void* callback_baton)
277 {
278     GetFormatManager().GetNamedSummaryNavigator().LoopThrough(callback, callback_baton);
279 }
280 
281 uint32_t
282 DataVisualization::NamedSummaryFormats::GetCount ()
283 {
284     return GetFormatManager().GetNamedSummaryNavigator().GetCount();
285 }
286