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