xref: /src/contrib/llvm-project/lldb/source/DataFormatters/DataVisualization.cpp (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1cfca06d7SDimitry Andric //===-- DataVisualization.cpp ---------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/DataFormatters/DataVisualization.h"
10f034231aSEd Maste 
11f034231aSEd Maste 
12f034231aSEd Maste using namespace lldb;
13f034231aSEd Maste using namespace lldb_private;
14f034231aSEd Maste 
GetFormatManager()1514f1b3e8SDimitry Andric static FormatManager &GetFormatManager() {
16f034231aSEd Maste   static FormatManager g_format_manager;
17f034231aSEd Maste   return g_format_manager;
18f034231aSEd Maste }
19f034231aSEd Maste 
ForceUpdate()2014f1b3e8SDimitry Andric void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); }
21f034231aSEd Maste 
GetCurrentRevision()2214f1b3e8SDimitry Andric uint32_t DataVisualization::GetCurrentRevision() {
23f034231aSEd Maste   return GetFormatManager().GetCurrentRevision();
24f034231aSEd Maste }
25f034231aSEd Maste 
ShouldPrintAsOneLiner(ValueObject & valobj)2614f1b3e8SDimitry Andric bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) {
27f21a844fSEd Maste   return GetFormatManager().ShouldPrintAsOneLiner(valobj);
28f034231aSEd Maste }
29f034231aSEd Maste 
30f034231aSEd Maste lldb::TypeFormatImplSP
GetFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)3114f1b3e8SDimitry Andric DataVisualization::GetFormat(ValueObject &valobj,
3214f1b3e8SDimitry Andric                              lldb::DynamicValueType use_dynamic) {
33f21a844fSEd Maste   return GetFormatManager().GetFormat(valobj, use_dynamic);
34f21a844fSEd Maste }
35f21a844fSEd Maste 
36f21a844fSEd Maste lldb::TypeFormatImplSP
GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)3714f1b3e8SDimitry Andric DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
38f21a844fSEd Maste   return GetFormatManager().GetFormatForType(type_sp);
39f034231aSEd Maste }
40f034231aSEd Maste 
41f034231aSEd Maste lldb::TypeSummaryImplSP
GetSummaryFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)4214f1b3e8SDimitry Andric DataVisualization::GetSummaryFormat(ValueObject &valobj,
4314f1b3e8SDimitry Andric                                     lldb::DynamicValueType use_dynamic) {
44f034231aSEd Maste   return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
45f034231aSEd Maste }
46f034231aSEd Maste 
47f034231aSEd Maste lldb::TypeSummaryImplSP
GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)4814f1b3e8SDimitry Andric DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
49f034231aSEd Maste   return GetFormatManager().GetSummaryForType(type_sp);
50f034231aSEd Maste }
51f034231aSEd Maste 
52f034231aSEd Maste lldb::SyntheticChildrenSP
GetSyntheticChildren(ValueObject & valobj,lldb::DynamicValueType use_dynamic)53f034231aSEd Maste DataVisualization::GetSyntheticChildren(ValueObject &valobj,
5414f1b3e8SDimitry Andric                                         lldb::DynamicValueType use_dynamic) {
55f034231aSEd Maste   return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
56f034231aSEd Maste }
57f034231aSEd Maste 
58f034231aSEd Maste lldb::TypeFilterImplSP
GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)5914f1b3e8SDimitry Andric DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
60f034231aSEd Maste   return GetFormatManager().GetFilterForType(type_sp);
61f034231aSEd Maste }
62f034231aSEd Maste 
63f034231aSEd Maste lldb::ScriptedSyntheticChildrenSP
GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)6414f1b3e8SDimitry Andric DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
65f034231aSEd Maste   return GetFormatManager().GetSyntheticForType(type_sp);
66f034231aSEd Maste }
67f034231aSEd Maste 
AnyMatches(const FormattersMatchCandidate & candidate_type,TypeCategoryImpl::FormatCategoryItems items,bool only_enabled,const char ** matching_category,TypeCategoryImpl::FormatCategoryItems * matching_type)6814f1b3e8SDimitry Andric bool DataVisualization::AnyMatches(
69e3b55780SDimitry Andric     const FormattersMatchCandidate &candidate_type,
70e3b55780SDimitry Andric     TypeCategoryImpl::FormatCategoryItems items, bool only_enabled,
71e3b55780SDimitry Andric     const char **matching_category,
7214f1b3e8SDimitry Andric     TypeCategoryImpl::FormatCategoryItems *matching_type) {
73e3b55780SDimitry Andric   return GetFormatManager().AnyMatches(candidate_type, items, only_enabled,
7414f1b3e8SDimitry Andric                                        matching_category, matching_type);
75f034231aSEd Maste }
76f034231aSEd Maste 
GetCategory(ConstString category,lldb::TypeCategoryImplSP & entry,bool allow_create)775f29bb8aSDimitry Andric bool DataVisualization::Categories::GetCategory(ConstString category,
7814f1b3e8SDimitry Andric                                                 lldb::TypeCategoryImplSP &entry,
7914f1b3e8SDimitry Andric                                                 bool allow_create) {
80f034231aSEd Maste   entry = GetFormatManager().GetCategory(category, allow_create);
815f29bb8aSDimitry Andric   return (entry.get() != nullptr);
82f034231aSEd Maste }
83f034231aSEd Maste 
GetCategory(lldb::LanguageType language,lldb::TypeCategoryImplSP & entry)8414f1b3e8SDimitry Andric bool DataVisualization::Categories::GetCategory(
8514f1b3e8SDimitry Andric     lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) {
8614f1b3e8SDimitry Andric   if (LanguageCategory *lang_category =
8714f1b3e8SDimitry Andric           GetFormatManager().GetCategoryForLanguage(language))
88e81d9d49SDimitry Andric     entry = lang_category->GetCategory();
89e81d9d49SDimitry Andric   return (entry.get() != nullptr);
90e81d9d49SDimitry Andric }
91e81d9d49SDimitry Andric 
Add(ConstString category)925f29bb8aSDimitry Andric void DataVisualization::Categories::Add(ConstString category) {
93f034231aSEd Maste   GetFormatManager().GetCategory(category);
94f034231aSEd Maste }
95f034231aSEd Maste 
Delete(ConstString category)965f29bb8aSDimitry Andric bool DataVisualization::Categories::Delete(ConstString category) {
97f034231aSEd Maste   GetFormatManager().DisableCategory(category);
98f034231aSEd Maste   return GetFormatManager().DeleteCategory(category);
99f034231aSEd Maste }
100f034231aSEd Maste 
Clear()10114f1b3e8SDimitry Andric void DataVisualization::Categories::Clear() {
102f034231aSEd Maste   GetFormatManager().ClearCategories();
103f034231aSEd Maste }
104f034231aSEd Maste 
Clear(ConstString category)1055f29bb8aSDimitry Andric void DataVisualization::Categories::Clear(ConstString category) {
106e3b55780SDimitry Andric   GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary);
107f034231aSEd Maste }
108f034231aSEd Maste 
Enable(ConstString category,TypeCategoryMap::Position pos)1095f29bb8aSDimitry Andric void DataVisualization::Categories::Enable(ConstString category,
11014f1b3e8SDimitry Andric                                            TypeCategoryMap::Position pos) {
111f034231aSEd Maste   if (GetFormatManager().GetCategory(category)->IsEnabled())
112f034231aSEd Maste     GetFormatManager().DisableCategory(category);
113706b4fc4SDimitry Andric   GetFormatManager().EnableCategory(category, pos, {});
114e81d9d49SDimitry Andric }
115e81d9d49SDimitry Andric 
Enable(lldb::LanguageType lang_type)11614f1b3e8SDimitry Andric void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) {
11714f1b3e8SDimitry Andric   if (LanguageCategory *lang_category =
11814f1b3e8SDimitry Andric           GetFormatManager().GetCategoryForLanguage(lang_type))
119e81d9d49SDimitry Andric     lang_category->Enable();
120f034231aSEd Maste }
121f034231aSEd Maste 
Disable(ConstString category)1225f29bb8aSDimitry Andric void DataVisualization::Categories::Disable(ConstString category) {
12394994d37SDimitry Andric   if (GetFormatManager().GetCategory(category)->IsEnabled())
124f034231aSEd Maste     GetFormatManager().DisableCategory(category);
125f034231aSEd Maste }
126f034231aSEd Maste 
Disable(lldb::LanguageType lang_type)12714f1b3e8SDimitry Andric void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) {
12814f1b3e8SDimitry Andric   if (LanguageCategory *lang_category =
12914f1b3e8SDimitry Andric           GetFormatManager().GetCategoryForLanguage(lang_type))
130e81d9d49SDimitry Andric     lang_category->Disable();
131e81d9d49SDimitry Andric }
132e81d9d49SDimitry Andric 
Enable(const lldb::TypeCategoryImplSP & category,TypeCategoryMap::Position pos)13314f1b3e8SDimitry Andric void DataVisualization::Categories::Enable(
13414f1b3e8SDimitry Andric     const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) {
13514f1b3e8SDimitry Andric   if (category.get()) {
136f034231aSEd Maste     if (category->IsEnabled())
137f034231aSEd Maste       GetFormatManager().DisableCategory(category);
138f034231aSEd Maste     GetFormatManager().EnableCategory(category, pos);
139f034231aSEd Maste   }
140f034231aSEd Maste }
141f034231aSEd Maste 
Disable(const lldb::TypeCategoryImplSP & category)14214f1b3e8SDimitry Andric void DataVisualization::Categories::Disable(
14314f1b3e8SDimitry Andric     const lldb::TypeCategoryImplSP &category) {
14494994d37SDimitry Andric   if (category.get() && category->IsEnabled())
145f034231aSEd Maste     GetFormatManager().DisableCategory(category);
146f034231aSEd Maste }
147f034231aSEd Maste 
EnableStar()14814f1b3e8SDimitry Andric void DataVisualization::Categories::EnableStar() {
149205afe67SEd Maste   GetFormatManager().EnableAllCategories();
150205afe67SEd Maste }
151205afe67SEd Maste 
DisableStar()15214f1b3e8SDimitry Andric void DataVisualization::Categories::DisableStar() {
153205afe67SEd Maste   GetFormatManager().DisableAllCategories();
154205afe67SEd Maste }
155205afe67SEd Maste 
ForEach(TypeCategoryMap::ForEachCallback callback)15614f1b3e8SDimitry Andric void DataVisualization::Categories::ForEach(
15714f1b3e8SDimitry Andric     TypeCategoryMap::ForEachCallback callback) {
158e81d9d49SDimitry Andric   GetFormatManager().ForEachCategory(callback);
159f034231aSEd Maste }
160f034231aSEd Maste 
GetCount()16114f1b3e8SDimitry Andric uint32_t DataVisualization::Categories::GetCount() {
162f034231aSEd Maste   return GetFormatManager().GetCategoriesCount();
163f034231aSEd Maste }
164f034231aSEd Maste 
165f034231aSEd Maste lldb::TypeCategoryImplSP
GetCategoryAtIndex(size_t index)16614f1b3e8SDimitry Andric DataVisualization::Categories::GetCategoryAtIndex(size_t index) {
167f034231aSEd Maste   return GetFormatManager().GetCategoryAtIndex(index);
168f034231aSEd Maste }
169f034231aSEd Maste 
GetSummaryFormat(ConstString type,lldb::TypeSummaryImplSP & entry)17014f1b3e8SDimitry Andric bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
1715f29bb8aSDimitry Andric     ConstString type, lldb::TypeSummaryImplSP &entry) {
172b60736ecSDimitry Andric   return GetFormatManager().GetNamedSummaryContainer().GetExact(type, entry);
173f034231aSEd Maste }
174f034231aSEd Maste 
Add(ConstString type,const lldb::TypeSummaryImplSP & entry)17514f1b3e8SDimitry Andric void DataVisualization::NamedSummaryFormats::Add(
1765f29bb8aSDimitry Andric     ConstString type, const lldb::TypeSummaryImplSP &entry) {
177b60736ecSDimitry Andric   GetFormatManager().GetNamedSummaryContainer().Add(type, entry);
178f034231aSEd Maste }
179f034231aSEd Maste 
Delete(ConstString type)1805f29bb8aSDimitry Andric bool DataVisualization::NamedSummaryFormats::Delete(ConstString type) {
181866dcdacSEd Maste   return GetFormatManager().GetNamedSummaryContainer().Delete(type);
182f034231aSEd Maste }
183f034231aSEd Maste 
Clear()18414f1b3e8SDimitry Andric void DataVisualization::NamedSummaryFormats::Clear() {
185866dcdacSEd Maste   GetFormatManager().GetNamedSummaryContainer().Clear();
186f034231aSEd Maste }
187f034231aSEd Maste 
ForEach(std::function<bool (const TypeMatcher &,const lldb::TypeSummaryImplSP &)> callback)18814f1b3e8SDimitry Andric void DataVisualization::NamedSummaryFormats::ForEach(
189b60736ecSDimitry Andric     std::function<bool(const TypeMatcher &, const lldb::TypeSummaryImplSP &)>
19014f1b3e8SDimitry Andric         callback) {
191e81d9d49SDimitry Andric   GetFormatManager().GetNamedSummaryContainer().ForEach(callback);
192f034231aSEd Maste }
193f034231aSEd Maste 
GetCount()19414f1b3e8SDimitry Andric uint32_t DataVisualization::NamedSummaryFormats::GetCount() {
195866dcdacSEd Maste   return GetFormatManager().GetNamedSummaryContainer().GetCount();
196f034231aSEd Maste }
197