1ac7ddfbfSEd Maste //===-- DataVisualization.cpp ---------------------------------------*- C++ -*-===// 2ac7ddfbfSEd Maste // 3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure 4ac7ddfbfSEd Maste // 5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source 6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details. 7ac7ddfbfSEd Maste // 8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===// 9ac7ddfbfSEd Maste 10ac7ddfbfSEd Maste #include "lldb/lldb-python.h" 11ac7ddfbfSEd Maste 12ac7ddfbfSEd Maste #include "lldb/DataFormatters/DataVisualization.h" 13ac7ddfbfSEd Maste 14ac7ddfbfSEd Maste // C Includes 15ac7ddfbfSEd Maste // C++ Includes 16ac7ddfbfSEd Maste // Other libraries and framework includes 17ac7ddfbfSEd Maste // Project includes 18ac7ddfbfSEd Maste 19ac7ddfbfSEd Maste #include "lldb/Core/Debugger.h" 20ac7ddfbfSEd Maste 21ac7ddfbfSEd Maste using namespace lldb; 22ac7ddfbfSEd Maste using namespace lldb_private; 23ac7ddfbfSEd Maste 24ac7ddfbfSEd Maste static FormatManager& 25ac7ddfbfSEd Maste GetFormatManager() 26ac7ddfbfSEd Maste { 27ac7ddfbfSEd Maste static FormatManager g_format_manager; 28ac7ddfbfSEd Maste return g_format_manager; 29ac7ddfbfSEd Maste } 30ac7ddfbfSEd Maste 31ac7ddfbfSEd Maste void 32ac7ddfbfSEd Maste DataVisualization::ForceUpdate () 33ac7ddfbfSEd Maste { 34ac7ddfbfSEd Maste GetFormatManager().Changed(); 35ac7ddfbfSEd Maste } 36ac7ddfbfSEd Maste 37ac7ddfbfSEd Maste uint32_t 38ac7ddfbfSEd Maste DataVisualization::GetCurrentRevision () 39ac7ddfbfSEd Maste { 40ac7ddfbfSEd Maste return GetFormatManager().GetCurrentRevision(); 41ac7ddfbfSEd Maste } 42ac7ddfbfSEd Maste 43ac7ddfbfSEd Maste lldb::TypeFormatImplSP 44ac7ddfbfSEd Maste DataVisualization::ValueFormats::GetFormat (ValueObject& valobj, lldb::DynamicValueType use_dynamic) 45ac7ddfbfSEd Maste { 46ac7ddfbfSEd Maste lldb::TypeFormatImplSP entry; 47ac7ddfbfSEd Maste GetFormatManager().GetValueNavigator().Get(valobj, entry, use_dynamic); 48ac7ddfbfSEd Maste return entry; 49ac7ddfbfSEd Maste } 50ac7ddfbfSEd Maste 51ac7ddfbfSEd Maste lldb::TypeFormatImplSP 52ac7ddfbfSEd Maste DataVisualization::ValueFormats::GetFormat (const ConstString &type) 53ac7ddfbfSEd Maste { 54ac7ddfbfSEd Maste lldb::TypeFormatImplSP entry; 55ac7ddfbfSEd Maste GetFormatManager().GetValueNavigator().Get(type, entry); 56ac7ddfbfSEd Maste return entry; 57ac7ddfbfSEd Maste } 58ac7ddfbfSEd Maste 59ac7ddfbfSEd Maste void 60ac7ddfbfSEd Maste DataVisualization::ValueFormats::Add (const ConstString &type, const lldb::TypeFormatImplSP &entry) 61ac7ddfbfSEd Maste { 62ac7ddfbfSEd Maste GetFormatManager().GetValueNavigator().Add(FormatManager::GetValidTypeName(type),entry); 63ac7ddfbfSEd Maste } 64ac7ddfbfSEd Maste 65ac7ddfbfSEd Maste bool 66ac7ddfbfSEd Maste DataVisualization::ValueFormats::Delete (const ConstString &type) 67ac7ddfbfSEd Maste { 68ac7ddfbfSEd Maste return GetFormatManager().GetValueNavigator().Delete(type); 69ac7ddfbfSEd Maste } 70ac7ddfbfSEd Maste 71ac7ddfbfSEd Maste void 72ac7ddfbfSEd Maste DataVisualization::ValueFormats::Clear () 73ac7ddfbfSEd Maste { 74ac7ddfbfSEd Maste GetFormatManager().GetValueNavigator().Clear(); 75ac7ddfbfSEd Maste } 76ac7ddfbfSEd Maste 77ac7ddfbfSEd Maste void 78ac7ddfbfSEd Maste DataVisualization::ValueFormats::LoopThrough (TypeFormatImpl::ValueCallback callback, void* callback_baton) 79ac7ddfbfSEd Maste { 80ac7ddfbfSEd Maste GetFormatManager().GetValueNavigator().LoopThrough(callback, callback_baton); 81ac7ddfbfSEd Maste } 82ac7ddfbfSEd Maste 83ac7ddfbfSEd Maste size_t 84ac7ddfbfSEd Maste DataVisualization::ValueFormats::GetCount () 85ac7ddfbfSEd Maste { 86ac7ddfbfSEd Maste return GetFormatManager().GetValueNavigator().GetCount(); 87ac7ddfbfSEd Maste } 88ac7ddfbfSEd Maste 89ac7ddfbfSEd Maste lldb::TypeNameSpecifierImplSP 90ac7ddfbfSEd Maste DataVisualization::ValueFormats::GetTypeNameSpecifierForFormatAtIndex (size_t index) 91ac7ddfbfSEd Maste { 92ac7ddfbfSEd Maste return GetFormatManager().GetValueNavigator().GetTypeNameSpecifierAtIndex(index); 93ac7ddfbfSEd Maste } 94ac7ddfbfSEd Maste 95ac7ddfbfSEd Maste lldb::TypeFormatImplSP 96ac7ddfbfSEd Maste DataVisualization::ValueFormats::GetFormatAtIndex (size_t index) 97ac7ddfbfSEd Maste { 98ac7ddfbfSEd Maste return GetFormatManager().GetValueNavigator().GetAtIndex(index); 99ac7ddfbfSEd Maste } 100ac7ddfbfSEd Maste 101ac7ddfbfSEd Maste lldb::TypeSummaryImplSP 102ac7ddfbfSEd Maste DataVisualization::GetSummaryFormat (ValueObject& valobj, 103ac7ddfbfSEd Maste lldb::DynamicValueType use_dynamic) 104ac7ddfbfSEd Maste { 105ac7ddfbfSEd Maste return GetFormatManager().GetSummaryFormat(valobj, use_dynamic); 106ac7ddfbfSEd Maste } 107ac7ddfbfSEd Maste 108ac7ddfbfSEd Maste lldb::TypeSummaryImplSP 109ac7ddfbfSEd Maste DataVisualization::GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp) 110ac7ddfbfSEd Maste { 111ac7ddfbfSEd Maste return GetFormatManager().GetSummaryForType(type_sp); 112ac7ddfbfSEd Maste } 113ac7ddfbfSEd Maste 114ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON 115ac7ddfbfSEd Maste lldb::SyntheticChildrenSP 116ac7ddfbfSEd Maste DataVisualization::GetSyntheticChildren (ValueObject& valobj, 117ac7ddfbfSEd Maste lldb::DynamicValueType use_dynamic) 118ac7ddfbfSEd Maste { 119ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic); 120ac7ddfbfSEd Maste } 121ac7ddfbfSEd Maste #endif 122ac7ddfbfSEd Maste 123ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON 124ac7ddfbfSEd Maste lldb::SyntheticChildrenSP 125ac7ddfbfSEd Maste DataVisualization::GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp) 126ac7ddfbfSEd Maste { 127ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticChildrenForType(type_sp); 128ac7ddfbfSEd Maste } 129ac7ddfbfSEd Maste #endif 130ac7ddfbfSEd Maste 131ac7ddfbfSEd Maste lldb::TypeFilterImplSP 132ac7ddfbfSEd Maste DataVisualization::GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp) 133ac7ddfbfSEd Maste { 134ac7ddfbfSEd Maste return GetFormatManager().GetFilterForType(type_sp); 135ac7ddfbfSEd Maste } 136ac7ddfbfSEd Maste 137ac7ddfbfSEd Maste #ifndef LLDB_DISABLE_PYTHON 138ac7ddfbfSEd Maste lldb::ScriptedSyntheticChildrenSP 139ac7ddfbfSEd Maste DataVisualization::GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp) 140ac7ddfbfSEd Maste { 141ac7ddfbfSEd Maste return GetFormatManager().GetSyntheticForType(type_sp); 142ac7ddfbfSEd Maste } 143ac7ddfbfSEd Maste #endif 144ac7ddfbfSEd Maste 145ac7ddfbfSEd Maste bool 146ac7ddfbfSEd Maste DataVisualization::AnyMatches (ConstString type_name, 147ac7ddfbfSEd Maste TypeCategoryImpl::FormatCategoryItems items, 148ac7ddfbfSEd Maste bool only_enabled, 149ac7ddfbfSEd Maste const char** matching_category, 150ac7ddfbfSEd Maste TypeCategoryImpl::FormatCategoryItems* matching_type) 151ac7ddfbfSEd Maste { 152ac7ddfbfSEd Maste return GetFormatManager().AnyMatches(type_name, 153ac7ddfbfSEd Maste items, 154ac7ddfbfSEd Maste only_enabled, 155ac7ddfbfSEd Maste matching_category, 156ac7ddfbfSEd Maste matching_type); 157ac7ddfbfSEd Maste } 158ac7ddfbfSEd Maste 159ac7ddfbfSEd Maste bool 160ac7ddfbfSEd Maste DataVisualization::Categories::GetCategory (const ConstString &category, lldb::TypeCategoryImplSP &entry, 161ac7ddfbfSEd Maste bool allow_create) 162ac7ddfbfSEd Maste { 163ac7ddfbfSEd Maste entry = GetFormatManager().GetCategory(category, allow_create); 164ac7ddfbfSEd Maste return (entry.get() != NULL); 165ac7ddfbfSEd Maste } 166ac7ddfbfSEd Maste 167ac7ddfbfSEd Maste void 168ac7ddfbfSEd Maste DataVisualization::Categories::Add (const ConstString &category) 169ac7ddfbfSEd Maste { 170ac7ddfbfSEd Maste GetFormatManager().GetCategory(category); 171ac7ddfbfSEd Maste } 172ac7ddfbfSEd Maste 173ac7ddfbfSEd Maste bool 174ac7ddfbfSEd Maste DataVisualization::Categories::Delete (const ConstString &category) 175ac7ddfbfSEd Maste { 176ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 177ac7ddfbfSEd Maste return GetFormatManager().DeleteCategory(category); 178ac7ddfbfSEd Maste } 179ac7ddfbfSEd Maste 180ac7ddfbfSEd Maste void 181ac7ddfbfSEd Maste DataVisualization::Categories::Clear () 182ac7ddfbfSEd Maste { 183ac7ddfbfSEd Maste GetFormatManager().ClearCategories(); 184ac7ddfbfSEd Maste } 185ac7ddfbfSEd Maste 186ac7ddfbfSEd Maste void 187ac7ddfbfSEd Maste DataVisualization::Categories::Clear (const ConstString &category) 188ac7ddfbfSEd Maste { 189ac7ddfbfSEd Maste GetFormatManager().GetCategory(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary); 190ac7ddfbfSEd Maste } 191ac7ddfbfSEd Maste 192ac7ddfbfSEd Maste void 193ac7ddfbfSEd Maste DataVisualization::Categories::Enable (const ConstString& category, 194ac7ddfbfSEd Maste TypeCategoryMap::Position pos) 195ac7ddfbfSEd Maste { 196ac7ddfbfSEd Maste if (GetFormatManager().GetCategory(category)->IsEnabled()) 197ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 198ac7ddfbfSEd Maste GetFormatManager().EnableCategory(category, pos); 199ac7ddfbfSEd Maste } 200ac7ddfbfSEd Maste 201ac7ddfbfSEd Maste void 202ac7ddfbfSEd Maste DataVisualization::Categories::Disable (const ConstString& category) 203ac7ddfbfSEd Maste { 204ac7ddfbfSEd Maste if (GetFormatManager().GetCategory(category)->IsEnabled() == true) 205ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 206ac7ddfbfSEd Maste } 207ac7ddfbfSEd Maste 208ac7ddfbfSEd Maste void 209ac7ddfbfSEd Maste DataVisualization::Categories::Enable (const lldb::TypeCategoryImplSP& category, 210ac7ddfbfSEd Maste TypeCategoryMap::Position pos) 211ac7ddfbfSEd Maste { 212ac7ddfbfSEd Maste if (category.get()) 213ac7ddfbfSEd Maste { 214ac7ddfbfSEd Maste if (category->IsEnabled()) 215ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 216ac7ddfbfSEd Maste GetFormatManager().EnableCategory(category, pos); 217ac7ddfbfSEd Maste } 218ac7ddfbfSEd Maste } 219ac7ddfbfSEd Maste 220ac7ddfbfSEd Maste void 221ac7ddfbfSEd Maste DataVisualization::Categories::Disable (const lldb::TypeCategoryImplSP& category) 222ac7ddfbfSEd Maste { 223ac7ddfbfSEd Maste if (category.get() && category->IsEnabled() == true) 224ac7ddfbfSEd Maste GetFormatManager().DisableCategory(category); 225ac7ddfbfSEd Maste } 226ac7ddfbfSEd Maste 227ac7ddfbfSEd Maste void 228ac7ddfbfSEd Maste DataVisualization::Categories::LoopThrough (FormatManager::CategoryCallback callback, void* callback_baton) 229ac7ddfbfSEd Maste { 230ac7ddfbfSEd Maste GetFormatManager().LoopThroughCategories(callback, callback_baton); 231ac7ddfbfSEd Maste } 232ac7ddfbfSEd Maste 233ac7ddfbfSEd Maste uint32_t 234ac7ddfbfSEd Maste DataVisualization::Categories::GetCount () 235ac7ddfbfSEd Maste { 236ac7ddfbfSEd Maste return GetFormatManager().GetCategoriesCount(); 237ac7ddfbfSEd Maste } 238ac7ddfbfSEd Maste 239ac7ddfbfSEd Maste lldb::TypeCategoryImplSP 240ac7ddfbfSEd Maste DataVisualization::Categories::GetCategoryAtIndex (size_t index) 241ac7ddfbfSEd Maste { 242ac7ddfbfSEd Maste return GetFormatManager().GetCategoryAtIndex(index); 243ac7ddfbfSEd Maste } 244ac7ddfbfSEd Maste 245ac7ddfbfSEd Maste bool 246ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::GetSummaryFormat (const ConstString &type, lldb::TypeSummaryImplSP &entry) 247ac7ddfbfSEd Maste { 248ac7ddfbfSEd Maste return GetFormatManager().GetNamedSummaryNavigator().Get(type,entry); 249ac7ddfbfSEd Maste } 250ac7ddfbfSEd Maste 251ac7ddfbfSEd Maste void 252ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::Add (const ConstString &type, const lldb::TypeSummaryImplSP &entry) 253ac7ddfbfSEd Maste { 254ac7ddfbfSEd Maste GetFormatManager().GetNamedSummaryNavigator().Add(FormatManager::GetValidTypeName(type),entry); 255ac7ddfbfSEd Maste } 256ac7ddfbfSEd Maste 257ac7ddfbfSEd Maste bool 258ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::Delete (const ConstString &type) 259ac7ddfbfSEd Maste { 260ac7ddfbfSEd Maste return GetFormatManager().GetNamedSummaryNavigator().Delete(type); 261ac7ddfbfSEd Maste } 262ac7ddfbfSEd Maste 263ac7ddfbfSEd Maste void 264ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::Clear () 265ac7ddfbfSEd Maste { 266ac7ddfbfSEd Maste GetFormatManager().GetNamedSummaryNavigator().Clear(); 267ac7ddfbfSEd Maste } 268ac7ddfbfSEd Maste 269ac7ddfbfSEd Maste void 270ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::LoopThrough (TypeSummaryImpl::SummaryCallback callback, void* callback_baton) 271ac7ddfbfSEd Maste { 272ac7ddfbfSEd Maste GetFormatManager().GetNamedSummaryNavigator().LoopThrough(callback, callback_baton); 273ac7ddfbfSEd Maste } 274ac7ddfbfSEd Maste 275ac7ddfbfSEd Maste uint32_t 276ac7ddfbfSEd Maste DataVisualization::NamedSummaryFormats::GetCount () 277ac7ddfbfSEd Maste { 278ac7ddfbfSEd Maste return GetFormatManager().GetNamedSummaryNavigator().GetCount(); 279ac7ddfbfSEd Maste } 280