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