Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1 | //===-- DataVisualization.cpp ---------------------------------------*- C++ |
| 2 | //-*-===// |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 11 | #include "lldb/DataFormatters/DataVisualization.h" |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 12 | |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 13 | |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 17 | static FormatManager &GetFormatManager() { |
| 18 | static FormatManager g_format_manager; |
| 19 | return g_format_manager; |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | void DataVisualization::ForceUpdate() { GetFormatManager().Changed(); } |
| 23 | |
| 24 | uint32_t DataVisualization::GetCurrentRevision() { |
| 25 | return GetFormatManager().GetCurrentRevision(); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | bool DataVisualization::ShouldPrintAsOneLiner(ValueObject &valobj) { |
| 29 | return GetFormatManager().ShouldPrintAsOneLiner(valobj); |
Enrico Granata | a29cb0b | 2013-10-04 23:14:13 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 32 | lldb::TypeFormatImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | DataVisualization::GetFormat(ValueObject &valobj, |
| 34 | lldb::DynamicValueType use_dynamic) { |
| 35 | return GetFormatManager().GetFormat(valobj, use_dynamic); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 38 | lldb::TypeFormatImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | DataVisualization::GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp) { |
| 40 | return GetFormatManager().GetFormatForType(type_sp); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | lldb::TypeSummaryImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | DataVisualization::GetSummaryFormat(ValueObject &valobj, |
| 45 | lldb::DynamicValueType use_dynamic) { |
| 46 | return GetFormatManager().GetSummaryFormat(valobj, use_dynamic); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 47 | } |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 48 | |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 49 | lldb::TypeSummaryImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | DataVisualization::GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp) { |
| 51 | return GetFormatManager().GetSummaryForType(type_sp); |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 54 | #ifndef LLDB_DISABLE_PYTHON |
Enrico Granata | 855cd90 | 2011-09-06 22:59:55 +0000 | [diff] [blame] | 55 | lldb::SyntheticChildrenSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | DataVisualization::GetSyntheticChildren(ValueObject &valobj, |
| 57 | lldb::DynamicValueType use_dynamic) { |
| 58 | return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 59 | } |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 60 | #endif |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 61 | |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 62 | #ifndef LLDB_DISABLE_PYTHON |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | lldb::SyntheticChildrenSP DataVisualization::GetSyntheticChildrenForType( |
| 64 | lldb::TypeNameSpecifierImplSP type_sp) { |
| 65 | return GetFormatManager().GetSyntheticChildrenForType(type_sp); |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 66 | } |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 67 | #endif |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 68 | |
| 69 | lldb::TypeFilterImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | DataVisualization::GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp) { |
| 71 | return GetFormatManager().GetFilterForType(type_sp); |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 74 | #ifndef LLDB_DISABLE_PYTHON |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 75 | lldb::ScriptedSyntheticChildrenSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 76 | DataVisualization::GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp) { |
| 77 | return GetFormatManager().GetSyntheticForType(type_sp); |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 78 | } |
Jason Molenda | 7a9a72b | 2012-05-16 00:38:08 +0000 | [diff] [blame] | 79 | #endif |
Enrico Granata | a777dc2 | 2012-05-08 21:49:57 +0000 | [diff] [blame] | 80 | |
Enrico Granata | c582713 | 2014-09-05 20:45:07 +0000 | [diff] [blame] | 81 | lldb::TypeValidatorImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | DataVisualization::GetValidator(ValueObject &valobj, |
| 83 | lldb::DynamicValueType use_dynamic) { |
| 84 | return GetFormatManager().GetValidator(valobj, use_dynamic); |
Enrico Granata | c582713 | 2014-09-05 20:45:07 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | lldb::TypeValidatorImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | DataVisualization::GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp) { |
| 89 | return GetFormatManager().GetValidatorForType(type_sp); |
Enrico Granata | c582713 | 2014-09-05 20:45:07 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | bool DataVisualization::AnyMatches( |
| 93 | ConstString type_name, TypeCategoryImpl::FormatCategoryItems items, |
| 94 | bool only_enabled, const char **matching_category, |
| 95 | TypeCategoryImpl::FormatCategoryItems *matching_type) { |
| 96 | return GetFormatManager().AnyMatches(type_name, items, only_enabled, |
| 97 | matching_category, matching_type); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | bool DataVisualization::Categories::GetCategory(const ConstString &category, |
| 101 | lldb::TypeCategoryImplSP &entry, |
| 102 | bool allow_create) { |
| 103 | entry = GetFormatManager().GetCategory(category, allow_create); |
| 104 | return (entry.get() != NULL); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | bool DataVisualization::Categories::GetCategory( |
| 108 | lldb::LanguageType language, lldb::TypeCategoryImplSP &entry) { |
| 109 | if (LanguageCategory *lang_category = |
| 110 | GetFormatManager().GetCategoryForLanguage(language)) |
| 111 | entry = lang_category->GetCategory(); |
| 112 | return (entry.get() != nullptr); |
Enrico Granata | 9eeabff | 2015-10-29 22:18:05 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | void DataVisualization::Categories::Add(const ConstString &category) { |
| 116 | GetFormatManager().GetCategory(category); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | bool DataVisualization::Categories::Delete(const ConstString &category) { |
| 120 | GetFormatManager().DisableCategory(category); |
| 121 | return GetFormatManager().DeleteCategory(category); |
| 122 | } |
| 123 | |
| 124 | void DataVisualization::Categories::Clear() { |
| 125 | GetFormatManager().ClearCategories(); |
| 126 | } |
| 127 | |
| 128 | void DataVisualization::Categories::Clear(const ConstString &category) { |
| 129 | GetFormatManager().GetCategory(category)->Clear( |
| 130 | eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); |
| 131 | } |
| 132 | |
| 133 | void DataVisualization::Categories::Enable(const ConstString &category, |
| 134 | TypeCategoryMap::Position pos) { |
| 135 | if (GetFormatManager().GetCategory(category)->IsEnabled()) |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 136 | GetFormatManager().DisableCategory(category); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | GetFormatManager().EnableCategory( |
| 138 | category, pos, std::initializer_list<lldb::LanguageType>()); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | void DataVisualization::Categories::Enable(lldb::LanguageType lang_type) { |
| 142 | if (LanguageCategory *lang_category = |
| 143 | GetFormatManager().GetCategoryForLanguage(lang_type)) |
| 144 | lang_category->Enable(); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 147 | void DataVisualization::Categories::Disable(const ConstString &category) { |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 148 | if (GetFormatManager().GetCategory(category)->IsEnabled()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | GetFormatManager().DisableCategory(category); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 152 | void DataVisualization::Categories::Disable(lldb::LanguageType lang_type) { |
| 153 | if (LanguageCategory *lang_category = |
| 154 | GetFormatManager().GetCategoryForLanguage(lang_type)) |
| 155 | lang_category->Disable(); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | void DataVisualization::Categories::Enable( |
| 159 | const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos) { |
| 160 | if (category.get()) { |
| 161 | if (category->IsEnabled()) |
| 162 | GetFormatManager().DisableCategory(category); |
| 163 | GetFormatManager().EnableCategory(category, pos); |
| 164 | } |
Enrico Granata | 964211f | 2015-09-04 22:07:48 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 167 | void DataVisualization::Categories::Disable( |
| 168 | const lldb::TypeCategoryImplSP &category) { |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 169 | if (category.get() && category->IsEnabled()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 170 | GetFormatManager().DisableCategory(category); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 173 | void DataVisualization::Categories::EnableStar() { |
| 174 | GetFormatManager().EnableAllCategories(); |
Enrico Granata | 964211f | 2015-09-04 22:07:48 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 177 | void DataVisualization::Categories::DisableStar() { |
| 178 | GetFormatManager().DisableAllCategories(); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 181 | void DataVisualization::Categories::ForEach( |
| 182 | TypeCategoryMap::ForEachCallback callback) { |
| 183 | GetFormatManager().ForEachCategory(callback); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 186 | uint32_t DataVisualization::Categories::GetCount() { |
| 187 | return GetFormatManager().GetCategoriesCount(); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 190 | lldb::TypeCategoryImplSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 191 | DataVisualization::Categories::GetCategoryAtIndex(size_t index) { |
| 192 | return GetFormatManager().GetCategoryAtIndex(index); |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | bool DataVisualization::NamedSummaryFormats::GetSummaryFormat( |
| 196 | const ConstString &type, lldb::TypeSummaryImplSP &entry) { |
| 197 | return GetFormatManager().GetNamedSummaryContainer().Get(type, entry); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 200 | void DataVisualization::NamedSummaryFormats::Add( |
| 201 | const ConstString &type, const lldb::TypeSummaryImplSP &entry) { |
| 202 | GetFormatManager().GetNamedSummaryContainer().Add( |
| 203 | FormatManager::GetValidTypeName(type), entry); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | bool DataVisualization::NamedSummaryFormats::Delete(const ConstString &type) { |
| 207 | return GetFormatManager().GetNamedSummaryContainer().Delete(type); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | void DataVisualization::NamedSummaryFormats::Clear() { |
| 211 | GetFormatManager().GetNamedSummaryContainer().Clear(); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | void DataVisualization::NamedSummaryFormats::ForEach( |
| 215 | std::function<bool(ConstString, const lldb::TypeSummaryImplSP &)> |
| 216 | callback) { |
| 217 | GetFormatManager().GetNamedSummaryContainer().ForEach(callback); |
Enrico Granata | 0a97614 | 2011-08-22 22:03:47 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | uint32_t DataVisualization::NamedSummaryFormats::GetCount() { |
| 221 | return GetFormatManager().GetNamedSummaryContainer().GetCount(); |
Enrico Granata | 4b49acc | 2011-08-22 23:45:15 +0000 | [diff] [blame] | 222 | } |