15ffd83dbSDimitry Andric //===-- DataVisualization.cpp ---------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/DataFormatters/DataVisualization.h"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric
120b57cec5SDimitry Andric using namespace lldb;
130b57cec5SDimitry Andric using namespace lldb_private;
140b57cec5SDimitry Andric
GetFormatManager()150b57cec5SDimitry Andric static FormatManager &GetFormatManager() {
160b57cec5SDimitry Andric static FormatManager g_format_manager;
170b57cec5SDimitry Andric return g_format_manager;
180b57cec5SDimitry Andric }
190b57cec5SDimitry Andric
ForceUpdate()200b57cec5SDimitry Andric void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); }
210b57cec5SDimitry Andric
GetCurrentRevision()220b57cec5SDimitry Andric uint32_t DataVisualization::GetCurrentRevision() {
230b57cec5SDimitry Andric return GetFormatManager().GetCurrentRevision();
240b57cec5SDimitry Andric }
250b57cec5SDimitry Andric
ShouldPrintAsOneLiner(ValueObject & valobj)260b57cec5SDimitry Andric bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) {
270b57cec5SDimitry Andric return GetFormatManager().ShouldPrintAsOneLiner(valobj);
280b57cec5SDimitry Andric }
290b57cec5SDimitry Andric
300b57cec5SDimitry Andric lldb::TypeFormatImplSP
GetFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)310b57cec5SDimitry Andric DataVisualization::GetFormat(ValueObject &valobj,
320b57cec5SDimitry Andric lldb::DynamicValueType use_dynamic) {
330b57cec5SDimitry Andric return GetFormatManager().GetFormat(valobj, use_dynamic);
340b57cec5SDimitry Andric }
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric lldb::TypeFormatImplSP
GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)370b57cec5SDimitry Andric DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) {
380b57cec5SDimitry Andric return GetFormatManager().GetFormatForType(type_sp);
390b57cec5SDimitry Andric }
400b57cec5SDimitry Andric
410b57cec5SDimitry Andric lldb::TypeSummaryImplSP
GetSummaryFormat(ValueObject & valobj,lldb::DynamicValueType use_dynamic)420b57cec5SDimitry Andric DataVisualization::GetSummaryFormat(ValueObject &valobj,
430b57cec5SDimitry Andric lldb::DynamicValueType use_dynamic) {
440b57cec5SDimitry Andric return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric
470b57cec5SDimitry Andric lldb::TypeSummaryImplSP
GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)480b57cec5SDimitry Andric DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) {
490b57cec5SDimitry Andric return GetFormatManager().GetSummaryForType(type_sp);
500b57cec5SDimitry Andric }
510b57cec5SDimitry Andric
520b57cec5SDimitry Andric lldb::SyntheticChildrenSP
GetSyntheticChildren(ValueObject & valobj,lldb::DynamicValueType use_dynamic)530b57cec5SDimitry Andric DataVisualization::GetSyntheticChildren(ValueObject &valobj,
540b57cec5SDimitry Andric lldb::DynamicValueType use_dynamic) {
550b57cec5SDimitry Andric return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
560b57cec5SDimitry Andric }
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric lldb::TypeFilterImplSP
GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)590b57cec5SDimitry Andric DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) {
600b57cec5SDimitry Andric return GetFormatManager().GetFilterForType(type_sp);
610b57cec5SDimitry Andric }
620b57cec5SDimitry Andric
630b57cec5SDimitry Andric lldb::ScriptedSyntheticChildrenSP
GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)640b57cec5SDimitry Andric DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) {
650b57cec5SDimitry Andric return GetFormatManager().GetSyntheticForType(type_sp);
660b57cec5SDimitry Andric }
670b57cec5SDimitry Andric
AnyMatches(ConstString type_name,TypeCategoryImpl::FormatCategoryItems items,bool only_enabled,const char ** matching_category,TypeCategoryImpl::FormatCategoryItems * matching_type)680b57cec5SDimitry Andric bool DataVisualization::AnyMatches(
690b57cec5SDimitry Andric ConstString type_name, TypeCategoryImpl::FormatCategoryItems items,
700b57cec5SDimitry Andric bool only_enabled, const char **matching_category,
710b57cec5SDimitry Andric TypeCategoryImpl::FormatCategoryItems *matching_type) {
720b57cec5SDimitry Andric return GetFormatManager().AnyMatches(type_name, items, only_enabled,
730b57cec5SDimitry Andric matching_category, matching_type);
740b57cec5SDimitry Andric }
750b57cec5SDimitry Andric
GetCategory(ConstString category,lldb::TypeCategoryImplSP & entry,bool allow_create)760b57cec5SDimitry Andric bool DataVisualization::Categories::GetCategory(ConstString category,
770b57cec5SDimitry Andric lldb::TypeCategoryImplSP &entry,
780b57cec5SDimitry Andric bool allow_create) {
790b57cec5SDimitry Andric entry = GetFormatManager().GetCategory(category, allow_create);
800b57cec5SDimitry Andric return (entry.get() != nullptr);
810b57cec5SDimitry Andric }
820b57cec5SDimitry Andric
GetCategory(lldb::LanguageType language,lldb::TypeCategoryImplSP & entry)830b57cec5SDimitry Andric bool DataVisualization::Categories::GetCategory(
840b57cec5SDimitry Andric lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) {
850b57cec5SDimitry Andric if (LanguageCategory *lang_category =
860b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(language))
870b57cec5SDimitry Andric entry = lang_category->GetCategory();
880b57cec5SDimitry Andric return (entry.get() != nullptr);
890b57cec5SDimitry Andric }
900b57cec5SDimitry Andric
Add(ConstString category)910b57cec5SDimitry Andric void DataVisualization::Categories::Add(ConstString category) {
920b57cec5SDimitry Andric GetFormatManager().GetCategory(category);
930b57cec5SDimitry Andric }
940b57cec5SDimitry Andric
Delete(ConstString category)950b57cec5SDimitry Andric bool DataVisualization::Categories::Delete(ConstString category) {
960b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
970b57cec5SDimitry Andric return GetFormatManager().DeleteCategory(category);
980b57cec5SDimitry Andric }
990b57cec5SDimitry Andric
Clear()1000b57cec5SDimitry Andric void DataVisualization::Categories::Clear() {
1010b57cec5SDimitry Andric GetFormatManager().ClearCategories();
1020b57cec5SDimitry Andric }
1030b57cec5SDimitry Andric
Clear(ConstString category)1040b57cec5SDimitry Andric void DataVisualization::Categories::Clear(ConstString category) {
1050b57cec5SDimitry Andric GetFormatManager().GetCategory(category)->Clear(
1060b57cec5SDimitry Andric eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1070b57cec5SDimitry Andric }
1080b57cec5SDimitry Andric
Enable(ConstString category,TypeCategoryMap::Position pos)1090b57cec5SDimitry Andric void DataVisualization::Categories::Enable(ConstString category,
1100b57cec5SDimitry Andric TypeCategoryMap::Position pos) {
1110b57cec5SDimitry Andric if (GetFormatManager().GetCategory(category)->IsEnabled())
1120b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
113480093f4SDimitry Andric GetFormatManager().EnableCategory(category, pos, {});
1140b57cec5SDimitry Andric }
1150b57cec5SDimitry Andric
Enable(lldb::LanguageType lang_type)1160b57cec5SDimitry Andric void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) {
1170b57cec5SDimitry Andric if (LanguageCategory *lang_category =
1180b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(lang_type))
1190b57cec5SDimitry Andric lang_category->Enable();
1200b57cec5SDimitry Andric }
1210b57cec5SDimitry Andric
Disable(ConstString category)1220b57cec5SDimitry Andric void DataVisualization::Categories::Disable(ConstString category) {
1230b57cec5SDimitry Andric if (GetFormatManager().GetCategory(category)->IsEnabled())
1240b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
1250b57cec5SDimitry Andric }
1260b57cec5SDimitry Andric
Disable(lldb::LanguageType lang_type)1270b57cec5SDimitry Andric void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) {
1280b57cec5SDimitry Andric if (LanguageCategory *lang_category =
1290b57cec5SDimitry Andric GetFormatManager().GetCategoryForLanguage(lang_type))
1300b57cec5SDimitry Andric lang_category->Disable();
1310b57cec5SDimitry Andric }
1320b57cec5SDimitry Andric
Enable(const lldb::TypeCategoryImplSP & category,TypeCategoryMap::Position pos)1330b57cec5SDimitry Andric void DataVisualization::Categories::Enable(
1340b57cec5SDimitry Andric const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) {
1350b57cec5SDimitry Andric if (category.get()) {
1360b57cec5SDimitry Andric if (category->IsEnabled())
1370b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
1380b57cec5SDimitry Andric GetFormatManager().EnableCategory(category, pos);
1390b57cec5SDimitry Andric }
1400b57cec5SDimitry Andric }
1410b57cec5SDimitry Andric
Disable(const lldb::TypeCategoryImplSP & category)1420b57cec5SDimitry Andric void DataVisualization::Categories::Disable(
1430b57cec5SDimitry Andric const lldb::TypeCategoryImplSP &category) {
1440b57cec5SDimitry Andric if (category.get() && category->IsEnabled())
1450b57cec5SDimitry Andric GetFormatManager().DisableCategory(category);
1460b57cec5SDimitry Andric }
1470b57cec5SDimitry Andric
EnableStar()1480b57cec5SDimitry Andric void DataVisualization::Categories::EnableStar() {
1490b57cec5SDimitry Andric GetFormatManager().EnableAllCategories();
1500b57cec5SDimitry Andric }
1510b57cec5SDimitry Andric
DisableStar()1520b57cec5SDimitry Andric void DataVisualization::Categories::DisableStar() {
1530b57cec5SDimitry Andric GetFormatManager().DisableAllCategories();
1540b57cec5SDimitry Andric }
1550b57cec5SDimitry Andric
ForEach(TypeCategoryMap::ForEachCallback callback)1560b57cec5SDimitry Andric void DataVisualization::Categories::ForEach(
1570b57cec5SDimitry Andric TypeCategoryMap::ForEachCallback callback) {
1580b57cec5SDimitry Andric GetFormatManager().ForEachCategory(callback);
1590b57cec5SDimitry Andric }
1600b57cec5SDimitry Andric
GetCount()1610b57cec5SDimitry Andric uint32_t DataVisualization::Categories::GetCount() {
1620b57cec5SDimitry Andric return GetFormatManager().GetCategoriesCount();
1630b57cec5SDimitry Andric }
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric lldb::TypeCategoryImplSP
GetCategoryAtIndex(size_t index)1660b57cec5SDimitry Andric DataVisualization::Categories::GetCategoryAtIndex(size_t index) {
1670b57cec5SDimitry Andric return GetFormatManager().GetCategoryAtIndex(index);
1680b57cec5SDimitry Andric }
1690b57cec5SDimitry Andric
GetSummaryFormat(ConstString type,lldb::TypeSummaryImplSP & entry)1700b57cec5SDimitry Andric bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
1710b57cec5SDimitry Andric ConstString type, lldb::TypeSummaryImplSP &entry) {
172*af732203SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().GetExact(type, entry);
1730b57cec5SDimitry Andric }
1740b57cec5SDimitry Andric
Add(ConstString type,const lldb::TypeSummaryImplSP & entry)1750b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::Add(
1760b57cec5SDimitry Andric ConstString type, const lldb::TypeSummaryImplSP &entry) {
177*af732203SDimitry Andric GetFormatManager().GetNamedSummaryContainer().Add(type, entry);
1780b57cec5SDimitry Andric }
1790b57cec5SDimitry Andric
Delete(ConstString type)1800b57cec5SDimitry Andric bool DataVisualization::NamedSummaryFormats::Delete(ConstString type) {
1810b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().Delete(type);
1820b57cec5SDimitry Andric }
1830b57cec5SDimitry Andric
Clear()1840b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::Clear() {
1850b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().Clear();
1860b57cec5SDimitry Andric }
1870b57cec5SDimitry Andric
ForEach(std::function<bool (const TypeMatcher &,const lldb::TypeSummaryImplSP &)> callback)1880b57cec5SDimitry Andric void DataVisualization::NamedSummaryFormats::ForEach(
189*af732203SDimitry Andric std::function<bool(const TypeMatcher &, const lldb::TypeSummaryImplSP &)>
1900b57cec5SDimitry Andric callback) {
1910b57cec5SDimitry Andric GetFormatManager().GetNamedSummaryContainer().ForEach(callback);
1920b57cec5SDimitry Andric }
1930b57cec5SDimitry Andric
GetCount()1940b57cec5SDimitry Andric uint32_t DataVisualization::NamedSummaryFormats::GetCount() {
1950b57cec5SDimitry Andric return GetFormatManager().GetNamedSummaryContainer().GetCount();
1960b57cec5SDimitry Andric }
197