15ffd83dbSDimitry 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 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 20*0b57cec5SDimitry Andric void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); } 21*0b57cec5SDimitry Andric 22*0b57cec5SDimitry Andric uint32_t DataVisualization::GetCurrentRevision() { 23*0b57cec5SDimitry Andric return GetFormatManager().GetCurrentRevision(); 24*0b57cec5SDimitry Andric } 25*0b57cec5SDimitry Andric 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 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 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 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 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 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 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 64*0b57cec5SDimitry Andric DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { 65*0b57cec5SDimitry Andric return GetFormatManager().GetSyntheticForType(type_sp); 66*0b57cec5SDimitry Andric } 67*0b57cec5SDimitry Andric 68*0b57cec5SDimitry Andric bool DataVisualization::AnyMatches( 69*0b57cec5SDimitry Andric ConstString type_name, TypeCategoryImpl::FormatCategoryItems items, 70*0b57cec5SDimitry Andric bool only_enabled, const char **matching_category, 71*0b57cec5SDimitry Andric TypeCategoryImpl::FormatCategoryItems *matching_type) { 72*0b57cec5SDimitry Andric return GetFormatManager().AnyMatches(type_name, items, only_enabled, 73*0b57cec5SDimitry Andric matching_category, matching_type); 74*0b57cec5SDimitry Andric } 75*0b57cec5SDimitry Andric 76*0b57cec5SDimitry Andric bool DataVisualization::Categories::GetCategory(ConstString category, 77*0b57cec5SDimitry Andric lldb::TypeCategoryImplSP &entry, 78*0b57cec5SDimitry Andric bool allow_create) { 79*0b57cec5SDimitry Andric entry = GetFormatManager().GetCategory(category, allow_create); 80*0b57cec5SDimitry Andric return (entry.get() != nullptr); 81*0b57cec5SDimitry Andric } 82*0b57cec5SDimitry Andric 83*0b57cec5SDimitry Andric bool DataVisualization::Categories::GetCategory( 84*0b57cec5SDimitry Andric lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) { 85*0b57cec5SDimitry Andric if (LanguageCategory *lang_category = 86*0b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(language)) 87*0b57cec5SDimitry Andric entry = lang_category->GetCategory(); 88*0b57cec5SDimitry Andric return (entry.get() != nullptr); 89*0b57cec5SDimitry Andric } 90*0b57cec5SDimitry Andric 91*0b57cec5SDimitry Andric void DataVisualization::Categories::Add(ConstString category) { 92*0b57cec5SDimitry Andric GetFormatManager().GetCategory(category); 93*0b57cec5SDimitry Andric } 94*0b57cec5SDimitry Andric 95*0b57cec5SDimitry Andric bool DataVisualization::Categories::Delete(ConstString category) { 96*0b57cec5SDimitry Andric GetFormatManager().DisableCategory(category); 97*0b57cec5SDimitry Andric return GetFormatManager().DeleteCategory(category); 98*0b57cec5SDimitry Andric } 99*0b57cec5SDimitry Andric 100*0b57cec5SDimitry Andric void DataVisualization::Categories::Clear() { 101*0b57cec5SDimitry Andric GetFormatManager().ClearCategories(); 102*0b57cec5SDimitry Andric } 103*0b57cec5SDimitry Andric 104*0b57cec5SDimitry Andric void DataVisualization::Categories::Clear(ConstString category) { 105*0b57cec5SDimitry Andric GetFormatManager().GetCategory(category)->Clear( 106*0b57cec5SDimitry Andric eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); 107*0b57cec5SDimitry Andric } 108*0b57cec5SDimitry Andric 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); 113480093f4SDimitry Andric GetFormatManager().EnableCategory(category, pos, {}); 114*0b57cec5SDimitry Andric } 115*0b57cec5SDimitry Andric 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 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 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 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 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 148*0b57cec5SDimitry Andric void DataVisualization::Categories::EnableStar() { 149*0b57cec5SDimitry Andric GetFormatManager().EnableAllCategories(); 150*0b57cec5SDimitry Andric } 151*0b57cec5SDimitry Andric 152*0b57cec5SDimitry Andric void DataVisualization::Categories::DisableStar() { 153*0b57cec5SDimitry Andric GetFormatManager().DisableAllCategories(); 154*0b57cec5SDimitry Andric } 155*0b57cec5SDimitry Andric 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 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 166*0b57cec5SDimitry Andric DataVisualization::Categories::GetCategoryAtIndex(size_t index) { 167*0b57cec5SDimitry Andric return GetFormatManager().GetCategoryAtIndex(index); 168*0b57cec5SDimitry Andric } 169*0b57cec5SDimitry Andric 170*0b57cec5SDimitry Andric bool DataVisualization::NamedSummaryFormats::GetSummaryFormat( 171*0b57cec5SDimitry Andric ConstString type, lldb::TypeSummaryImplSP &entry) { 172*0b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().Get(type, entry); 173*0b57cec5SDimitry Andric } 174*0b57cec5SDimitry Andric 175*0b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::Add( 176*0b57cec5SDimitry Andric ConstString type, const lldb::TypeSummaryImplSP &entry) { 177*0b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().Add( 178*0b57cec5SDimitry Andric FormatManager::GetValidTypeName(type), entry); 179*0b57cec5SDimitry Andric } 180*0b57cec5SDimitry Andric 181*0b57cec5SDimitry Andric bool DataVisualization::NamedSummaryFormats::Delete(ConstString type) { 182*0b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().Delete(type); 183*0b57cec5SDimitry Andric } 184*0b57cec5SDimitry Andric 185*0b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::Clear() { 186*0b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().Clear(); 187*0b57cec5SDimitry Andric } 188*0b57cec5SDimitry Andric 189*0b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::ForEach( 190*0b57cec5SDimitry Andric std::function<bool(ConstString, const lldb::TypeSummaryImplSP &)> 191*0b57cec5SDimitry Andric callback) { 192*0b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().ForEach(callback); 193*0b57cec5SDimitry Andric } 194*0b57cec5SDimitry Andric 195*0b57cec5SDimitry Andric uint32_t DataVisualization::NamedSummaryFormats::GetCount() { 196*0b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().GetCount(); 197*0b57cec5SDimitry Andric } 198